Skip to content

Spurious "A type predicate's type must be assignable to its parameter's type" #21185

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
pelotom opened this issue Jan 15, 2018 · 2 comments
Closed
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@pelotom
Copy link

pelotom commented Jan 15, 2018

TypeScript Version: 2.7.0-dev.20180113

Code

This type operator from the Unionize library:

type Predicates<TaggedRecord> = {
  [T in keyof TaggedRecord]: (variant: TaggedRecord[keyof TaggedRecord]) => variant is TaggedRecord[T]
}

Expected behavior:

Should compile, and does in [email protected].

Actual behavior:

Fails to compile in typescript@next with

A type predicate's type must be assignable to its parameter's type.
  Type 'TaggedRecord[T]' is not assignable to type 'TaggedRecord[keyof TaggedRecord]'.
@ghost ghost added the Bug A bug in TypeScript label Jan 16, 2018
@mhegazy mhegazy added this to the TypeScript 2.7.1 milestone Jan 16, 2018
@sandersn
Copy link
Member

Caused by #17912. Before that, the assignability was not checked at all; the constraint of both types was incorrectly any. Now, neither type has a constraint, so they are incorrectly not assignable. Turns out our assignability rules for indexed access types are incomplete.

I'll put up a PR after lunch; I need to write some more tests.

@sandersn
Copy link
Member

Fix is up at #21242

@sandersn sandersn added the Fixed A PR has been merged for this issue label Jan 17, 2018
@microsoft microsoft locked and limited conversation to collaborators Jul 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

3 participants