Skip to content

Fix missing constraints for parenthesized infer T #40406

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

Merged
merged 3 commits into from
Sep 23, 2020

Conversation

uhyo
Copy link
Contributor

@uhyo uhyo commented Sep 6, 2020

Fixes #30502.

This bug was one of the causes of the recent release of Prettier 2.1.1 😄

Example

type F1 = (num: [number])=>void;
type IsNumber<T extends number> = T;

type T1 = F1 extends (...args: (infer T)) => void ? T : never;
type T2 = F1 extends (args: [...(infer T)]) => void ? T : never;
type T3<T> = T extends IsNumber<(infer N)> ? true : false;

Current Behavior

test.ts:5:23 - error TS2370: A rest parameter must be of an array type.

5 type T1 = F1 extends (...args: (infer T)) => void ? T : never;
                        ~~~~~~~~~~~~~~~~~~

test.ts:7:30 - error TS2574: A rest element type must be an array type.

7 type T2 = F1 extends (args: [...(infer T)]) => void ? T : never;
                               ~~~~~~~~~~~~

test.ts:8:33 - error TS2344: Type 'N' does not satisfy the constraint 'number'.

8 type T3<T> = T extends IsNumber<(infer N)> ? true : false;
                                  ~~~~~~~~~


Found 3 errors.

New Behavior

No errors.

@typescript-bot typescript-bot added the For Backlog Bug PRs that fix a backlog bug label Sep 6, 2020
@sandersn sandersn requested a review from weswigham September 22, 2020 22:55
@weswigham weswigham merged commit 61910e8 into microsoft:master Sep 23, 2020
@uhyo uhyo deleted the fix-30502 branch September 23, 2020 09:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Backlog Bug PRs that fix a backlog bug
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Parentheses around infer T in rest parameter position leads to an error
3 participants