Skip to content

No type inferrence of callback arguments inside a tuple union typeΒ #55632

@nenikitov

Description

@nenikitov

πŸ”Ž Search Terms

  • discriminated union inference
  • union argument inference

πŸ•— Version & Regression Information

  • This is a compilation error in tsserver 3.3.2

⏯ Playground Link

https://www.typescriptlang.org/play?#code/C4TwDgpgBAkgdgMwgJwILIOZQLwCgpQA+UA2gIwA0UAFAIYBcUcArgLYBGKAlDgHxQA3APYBLACYBdfEVIAmKtXaMAzsGQi4GHtn7DxEgNy4AxkLiqotTI3hI0mHKUo1a2-gG8oAX0O4gA

πŸ’» Code

type InferArg =
  | [1, (a: number) => void]
  | [2, (b: string) => void];
const arg: InferArg = [1, (a) => { }];

πŸ™ Actual behavior

I get a compilation error:

Parameter 'a' implicitly has an 'any' type.(7006)

πŸ™‚ Expected behavior

a should be inferred to be a number because I already passed 1 as the first tuple element. Type inference should be identical to this code:

type InferArg = [1, (a: number) => void];
const arg: InferArg = [1, (a) => { }];

Additional information about the issue

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: check: Type InferenceRelated to type inference performed during signature resolution or `infer` type resolutionHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions