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 no longer write deep predicates in conditional types #52271

Closed
geoffreytools opened this issue Jan 17, 2023 · 5 comments Β· Fixed by #52333
Closed

Can no longer write deep predicates in conditional types #52271

geoffreytools opened this issue Jan 17, 2023 · 5 comments Β· Fixed by #52333
Assignees
Labels
Bug A bug in TypeScript

Comments

@geoffreytools
Copy link

Bug Report

πŸ”Ž Search Terms

conditional types, generics, deep, predicate

πŸ•— Version & Regression Information

This changed between versions 4.8.4 and 4.9.4

⏯ Playground Link

Playground link with the code bellow

πŸ’» Code

type Foo<A,B> = [A, B] extends unknown[][] ? Bar<[A, B]> : 'else'
//                                               ~~~~~~
// Type '[A, B]' does not satisfy the constraint 'unknown[][]'.

type Bar<T extends unknown[][]> = T

This is not limited to tuples

type Foo<A> = Set<A> extends Set<unknown[]> ? Bar<Set<A>> : 'else'
//                                                ~~~~~
// Type 'Set<A>' does not satisfy the constraint 'Set<unknown[]>'.

type Bar<T extends Set<unknown[]>> = T

πŸ™ Actual behavior

There is a type error that literally contradicts the predicate of the conditional

πŸ™‚ Expected behavior

It should compile with no error

@jakebailey
Copy link
Member

jakebailey commented Jan 20, 2023

Both of these compile in nightly (soon to be beta) as of #51621, so this looks to be a duplicate of #51614.

(Flip your playground to nightly to see.)

@geoffreytools
Copy link
Author

It's great that it is fixed but it must have been in a different PR, or maybe it was an unintentional side-effect, because these 2 issues are not related to me: the outcome of the conditional cannot be known here.

I feel that a test case should be added for this scenario if it hasn't been already.

@jakebailey
Copy link
Member

That PR definitely fixed it; I bisected to confirm before replying.

@jakebailey
Copy link
Member

I've also checked and it was #50397 which regressed this.

jakebailey added a commit to jakebailey/TypeScript that referenced this issue Jan 20, 2023
jakebailey added a commit to jakebailey/TypeScript that referenced this issue Jan 20, 2023
@jakebailey
Copy link
Member

Sent #52333 with a test.

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Jan 23, 2023
jakebailey added a commit that referenced this issue Jan 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants