Skip to content

Constraint generics param does not satisfy type infer expression. #50606

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
thynson opened this issue Sep 2, 2022 · 2 comments
Closed

Constraint generics param does not satisfy type infer expression. #50606

thynson opened this issue Sep 2, 2022 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@thynson
Copy link

thynson commented Sep 2, 2022

Bug Report

πŸ”Ž Search Terms

Constraint generics param does not satisfy type infer expression.

πŸ•— Version & Regression Information

4.7.4 and 4.8.2, earlier versions may behave the same.

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

type Types<T> = (T extends {} ? 'object' : never ) | 'primitive'

function accept<T>(a: Types<T>) {
}

function b<T extends {}>(a: T) {
    accept<T>('primitive'); // Okay
    accept<T>('object'); // Error: TS2345
    accept<T & object>('object'); // Okay, but T already extends from {}, such workaround shall not be required
}

πŸ™ Actual behavior

tsc accepts the above code

πŸ™‚ Expected behavior

the above code is rejected

@whzx5byb
Copy link

whzx5byb commented Sep 2, 2022

Duplicate of #31096

@jakebailey jakebailey added the Duplicate An existing issue was already created label Sep 2, 2022
@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants