🔎 Search Terms
Function parameter
🕗 Version & Regression Information
- This changed between versions ______ and _______
- This changed in commit or PR _______
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________
- I was unable to test this on prior versions because _______
⏯ Playground Link
https://www.typescriptlang.org/zh/play/?#code/KYOwrgtgBAKgngB2FA3gWAFBSgQQDSbYBCBGAvppgJYgAuwATgGYCGAxsvEgLIsKqEoAbS7AAdDgC6ALigBnWgxoBzANyCRicURlRwEAEaN15ShlpaoADQA8MKMAAe9EABM5sLQD4oAXmyivAgikiaYTGAgbLRUAPYgUBFRdg7OoO6eSF4AFBZIsjB4qS6usrYwXgCUAlhQVExQuZa+LZniONXotdgA9D1QAOoAFnBQAEROJWNQechUHiCxtPKKKlAA-IK9-dkILAwsEMD0DNWT6bIKSiDKUAA+epBGDPdQBrGxADbALCBbUGx4nIvuJPrFlE0kEVzm5KiZsBRTBhwpE2NlRBIigByLFwlFRdFaMQkKAARjhQA
💻 Code
enumType{A,B,}interfaceTypeMap{[Type.A]: string;[Type.B]: number;}typeX<TextendsType>=TypeMap[T];functionfunc<TextendsType>(type: T,extend: X<T>){if(type===Type.A){// Why "extend" type is not string ?// (parameter) extend: string | number | booleanconsole.log(type,extend);}}func(Type.A,'');func(Type.B,1);🙁 Actual behavior
In the example, Why "extend" type is not string ?
🙂 Expected behavior
The "type" constrained to "Type.A",so "extend" shuld be "string".
Additional information about the issue
No response
🔎 Search Terms
Function parameter
🕗 Version & Regression Information
⏯ Playground Link
https://www.typescriptlang.org/zh/play/?#code/KYOwrgtgBAKgngB2FA3gWAFBSgQQDSbYBCBGAvppgJYgAuwATgGYCGAxsvEgLIsKqEoAbS7AAdDgC6ALigBnWgxoBzANyCRicURlRwEAEaN15ShlpaoADQA8MKMAAe9EABM5sLQD4oAXmyivAgikiaYTGAgbLRUAPYgUBFRdg7OoO6eSF4AFBZIsjB4qS6usrYwXgCUAlhQVExQuZa+LZniONXotdgA9D1QAOoAFnBQAEROJWNQechUHiCxtPKKKlAA-IK9-dkILAwsEMD0DNWT6bIKSiDKUAA+epBGDPdQBrGxADbALCBbUGx4nIvuJPrFlE0kEVzm5KiZsBRTBhwpE2NlRBIigByLFwlFRdFaMQkKAARjhQA
💻 Code
🙁 Actual behavior
In the example, Why "extend" type is not string ?
🙂 Expected behavior
The "type" constrained to "Type.A",so "extend" shuld be "string".
Additional information about the issue
No response