We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Originally commented over here: #48326 (comment)
spread, ternary, object spread, union, property
Playground link with relevant code
function fn(h: { a: string; b?: never; c?: never } | { a: string; b: string; c: string }) {} let data = 'a' as 'a' | undefined; // β This works in TS fn(data ? { a: '', b: '', c: data } : { a: '' }); // β TS cannot figure this option out, even though it's also valid fn({ a: '', ...(data ? { b: '', c: data } : {}), }); // β This works in TS fn({ a: '', ...(data ? { b: '', c: data } : {} as {[key: string]: never}), });
b was recognized to be a string | undefined, although it's only possible to be a string
b
string | undefined
string
b should only be a string
The text was updated successfully, but these errors were encountered:
We had to change this behavior in 4.2 to avoid an exponential explosion caused by repeated spreads in the same object.
Sorry, something went wrong.
Thread with more context
Ok thanks, closing :)
No branches or pull requests
Bug Report
Originally commented over here: #48326 (comment)
π Search Terms
spread, ternary, object spread, union, property
π Version & Regression Information
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
b
was recognized to be astring | undefined
, although it's only possible to be astring
π Expected behavior
b
should only be astring
The text was updated successfully, but these errors were encountered: