Bug Report
Hello 👋🏻
I'm facing some strange issue with Generics. Until I specify input arguments in function all generics are inferred correctly. But as soon as I mention argument in function the inference is broken.
Thanks in advance for any help 🙏🏻
🔎 Search Terms
- generic is lost after specifying input arguments
- typescript generic unknown after specifying arguments (found this stackoverflow but not sure if it's the same case)
🕗 Version & Regression Information
typescript: 4.2.3
Also tried nightly build but the issue remains
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about Generics_____
⏯ Playground Link
Workbench Repro
💻 Code
typeConnector=<AccessToken>(opts: {getAccessToken(input: {code: string}): Promise<AccessToken>;validateAuth(input: {fields: AccessToken}): Promise<{name: string}>;})=>any;constconnector: Connector=(inp)=>undefinedconnector({getAccessToken: async()=>({token: 'token'}),validateAuth: async({fields})=>{//fields: {token: string}// ^?return{name: 'qwe'}}})connector({getAccessToken: async(inp)=>({token: 'token'}),// mention input argument breaks inferencevalidateAuth: async({fields})=>{// fields: unknown// ^?return{name: 'qwe'}}})🙁 Actual behavior
fields inside validateAuth infer to unknown after using function argument in getAccessToken. Until I use arguments everything works OK
🙂 Expected behavior
Usage of function arguments inside getAccessToken should not affect Generic inference since they are statically type
Bug Report
Hello 👋🏻
I'm facing some strange issue with Generics. Until I specify input arguments in function all generics are inferred correctly. But as soon as I mention argument in function the inference is broken.
Thanks in advance for any help 🙏🏻
🔎 Search Terms
🕗 Version & Regression Information
typescript: 4.2.3
Also tried nightly build but the issue remains
⏯ Playground Link
Workbench Repro
💻 Code
🙁 Actual behavior
fieldsinsidevalidateAuthinfer to unknown after using function argument ingetAccessToken. Until I use arguments everything works OK🙂 Expected behavior
Usage of function arguments inside
getAccessTokenshould not affect Generic inference since they are statically type