Skip to content
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

Can't infer constrained types #21631

Closed
falsandtru opened this issue Feb 5, 2018 · 1 comment
Closed

Can't infer constrained types #21631

falsandtru opened this issue Feb 5, 2018 · 1 comment
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@falsandtru
Copy link
Contributor

falsandtru commented Feb 5, 2018

@ahejlsberg You mean this?

Note that is not possible for a conditional type to recursively reference itself, as might be desired in the Unpacked case above. We're still considering ways in which to implement this.

TypeScript Version: master

Search Terms:

Code

type A<T, U extends A<any, any>> = [T, U];
type B<S> = S extends A<infer T, infer U> ? [T, U] : never;

Expected behavior:

pass

Actual behavior:

$ node built/local/tsc.js --noEmit index.ts
index.ts(2,34): error TS2344: Type 'U' does not satisfy the constraint '[any, an
y]'.

Related Issues:

@falsandtru
Copy link
Contributor Author

No, probably this:

The definitely assignable relation is the same as the regular assignable relation, except that type variable constraints are not considered.

We may at a later date support infer declarations in regular type parameter constraints, however it is not trivial to implement. Meanwhile, you can get much the same effect with the existing constraint mechanism as I explain in the introduction to the PR.

#21496 (comment)

type A<T, U extends void> = [T, U];
type B<S> = S extends A<infer T, infer U> ? [T, U] : never;
type C<S, U extends void> = S extends A<infer T, U> ? [T, U] : never;
$ node built/local/tsc.js --noEmit index.ts
index.ts(2,34): error TS2344: Type 'U' does not satisfy the constraint 'void'.

@falsandtru falsandtru changed the title Can't infer recursive constrained types Can't infer constrained types Feb 5, 2018
@mhegazy mhegazy added the Bug A bug in TypeScript label Feb 5, 2018
@mhegazy mhegazy added this to the TypeScript 2.8 milestone Feb 5, 2018
@ahejlsberg ahejlsberg added the Fixed A PR has been merged for this issue label Feb 7, 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