- Notifications
You must be signed in to change notification settings - Fork 13.2k
Open
Labels
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScriptAn idea for TypeScript
Description
TypeScript Version: 3.7.0-dev.20191015
Search Terms: type discrimination, callable, signatures, implicit any
Code
function test( a: | { type?: 1; property: (a: number) => void } | { type: 2; property: (a: string) => void }, ) { return a.property } test({ property: (x) => { // complaining that x implicitly has type any console.log('hi') }, })Expected behavior:
x should be inferred to be number.
Actual behavior:
x is any.
If you change type?: 1 to type: 1, it works as expected.
Playground Link: link
Related Issues: #7294 (closed with #29011 - see second half of the original post, I believe it describes why this issue occurs)
Metadata
Metadata
Assignees
Labels
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScriptAn idea for TypeScript