-
Notifications
You must be signed in to change notification settings - Fork 12.8k
ternary operator with an empty object always gives an empty object #14758
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I think its caused by subtype reduction. Unfortunately I've stumbled upon a similar issue, where because of #13039 (comment) the reduction is unsafe: #12970. |
It's really dangerous, also code like this which looks to be properly typed can silently introduce errors to codebase: interface IObject {
foo?: boolean;
}
const fooBar: IObject = true ? {
foo: 'not boolean', // should be boolean only
notExisting: '132' // should not exist
} : {}; It's always taking |
|
by the same logic |
well, yes, |
i love your sense of humor, dear sir |
How come this behaviour only applies to ternary operators, not functions? // expected error, but got none!
const x2: { blur?: string } = 'foo' ? { blur: 1 } : {};
// expected error, got error
const x3: { blur?: string } = (() => {
if ('foo') {
return { blur: 1 };
} else {
return {};
}
})(); |
Tracking this at #19236 |
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed. |
The text was updated successfully, but these errors were encountered: