Skip to content

Optional discriminated union's callback parameter type is not inferred #46847

@wzono

Description

@wzono

Bug Report

Optional discriminated union's callback parameter type is not inferred

🔎 Search Terms

#35769

🕗 Version & Regression Information

typescript@4.4.4

⏯ Playground Link

https://www.typescriptlang.org/play?ts=4.5.0-beta#code/C4TwDgpgBAglC8UDeAoK6qkgfgFxQHIYCAaNDAQ3wAoBjfJKAE3wDsBXAWwCMIAnKAF8AlAgB8UAG4B7AJZMA3CkEoUWaACEEycunX4CG0rqhUodBszZdefElHpQAzsD6zWAcyGj4EmfKUVVXVYDQBhbTgAHygtJRRJCgEzGHCAbQBdKBiAJQhaaT4mAB4XN097VLDMiUQ0k1QMJtMaMCSKTicfCUbmvpMmlUGUDKA

💻 Code

type A = {
    type?: 'A',
    a: (c: { d: number }) => void;
}

type B = {
    type: 'B',
    a: (c: { d: number, c: string }) => void;
}


type ABC = A | B ;

var a: ABC[] | Record<string, ABC[]> = [
    {
        a: (params) => {
            
        }
    }
]

🙁 Actual behavior

Parameters of method 'a' can not be inferred correctly.

🙂 Expected behavior

Parameters of method 'a 'can be inferred correctly: {d: number}

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: check: Type InferenceRelated to type inference performed during signature resolution or `infer` type resolution

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions