Skip to content

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

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}

Activity

  1. RyanCavanaugh commented on Nov 18, 2021

    @RyanCavanaugh
    Member

    Behavior dates back to at least 3.3.3. It looks like our discriminant detection is getting a little confused by the Record part of the union.

  2. wzono commented on Dec 10, 2021

    @wzono
    Author
  3. RyanCavanaugh commented on Dec 13, 2021

    @RyanCavanaugh
    Member

    @wingsico no

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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