Microsoft/TypeScript
GitHub ã§èŠãNo type inferrence of callback arguments inside a tuple union type
Open
#55,632 opened on 2023幎9æ5æ¥
BugDomain: check: Type InferenceHelp Wanted
Repository metrics
- Stars
- Â (48,455 stars)
- PR merge metrics
-  (å¹³åããŒãž 6d 17h) (30d ã§ 9 merged PRs)
説æ
ð Search Terms
- discriminated union inference
- union argument inference
ð Version & Regression Information
- This is a compilation error in
tsserver 3.3.2
⯠Playground Link
ð» 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