-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Combination of generic type and mapped types produce unexpected bahaviour #32807
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
Comments
This is working as intended.
The conditional type is distributive so it’s not possible to correctly predict the behaviour until Discussion here #31751. type R<T, N extends keyof T> = {
[P in keyof T]: [P] extends [N] ? true : false
}; I think this should work. |
Thanks for your explanation! |
This issue has been marked as 'Question' and has seen no recent activity. It has been automatically closed for house-keeping purposes. If you're still waiting on a response, questions are usually better suited to stackoverflow. |
2 similar comments
This issue has been marked as 'Question' and has seen no recent activity. It has been automatically closed for house-keeping purposes. If you're still waiting on a response, questions are usually better suited to stackoverflow. |
This issue has been marked as 'Question' and has seen no recent activity. It has been automatically closed for house-keeping purposes. If you're still waiting on a response, questions are usually better suited to stackoverflow. |
I've tried my best to search for related issues and read the document thoroughly but failed to find any useful information. I'm sorry if this bug turns out to be duplicate or even not a bug at all.
TypeScript Version: 3.5.2
Search Terms: conditional types, mapped types, generic
Code
Expected behavior:
Any property of type
R<T,K>
could be assigned totrue
if it extends typeK
; Thereforetrue
could be assigned totemp[key]
;Actual behavior:
Error in function
fn2
I suppose type
K extends K ? true : false
should be automatically resolved to typetrue
.Playground Link:
Playground Link
I also test the same function with a concrete type and it works as expected. And even if I implement type
R
without conditional types (Q
in example code), the bug still exists, so I guess there is nothing to do with conditional types, but mapped types and generic type;The text was updated successfully, but these errors were encountered: