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

[email protected]

⏯ 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 TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions