- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.1k
Closed
Labels
Design LimitationConstraints of the existing architecture prevent this from being fixedConstraints of the existing architecture prevent this from being fixed
Description
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
💻 Code
type Connector = <
    AccessToken
>(opts: {
    getAccessToken(input: {code: string}): Promise<AccessToken>;
    validateAuth(input: {fields: AccessToken}): Promise<{name: string}>;
}) => any;
const connector: Connector = (inp) => undefined
connector({
    getAccessToken: async () => ({token: 'token'}),
    validateAuth: async ({fields}) => { //fields: {token: string}
        //                  ^?
        return {name: 'qwe'}
    }
})
connector({
    getAccessToken: async (inp) => ({token: 'token'}), // mention input argument breaks inference
    validateAuth: 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
ilogico, leandro-manifesto, jakst, JonKrone, ArturBaybulatov and 2 more
Metadata
Metadata
Assignees
Labels
Design LimitationConstraints of the existing architecture prevent this from being fixedConstraints of the existing architecture prevent this from being fixed