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
.
https://www.typescriptlang.org/play?#code/C4TwDgpgBAsiAq5oF4BQUNQD5QN5QDsBDAWwgC4oBnYAJwEsCBzKAX3Ux32LMpoeYBuKAHswweiOIAbSnQCu0dqgDGUmlBIgAakWmKoyPBww8KUAEQWANCdHjJMyvIIATCADNGEV9agB6fygAdQB5ACUAaQBlPwAhAFV4KABJKABRAA0ABXSAYWSU5PhQjPDwiNR2IA
type MyType = | { name: string } | { name: string; optional: true }
const myValue = { name: "", optional: undefined, // WORKS }
const myValue = { name: "", optional: undefined, // ERROR: Type 'undefined' is not assignable to type 'true'. }
I don't know if this should be a bug report or a feature request.
The text was updated successfully, but these errors were encountered:
Not a bug. { name: "", optional: undefined } is assignable to { name: string } due to structural subtyping. You're looking for #12936.
{ name: "", optional: undefined }
{ name: string }
Sorry, something went wrong.
Optional object property that must be a [specific] type and can't be undefined
The above having been said: if this is your only use case for the requested behavior, then you can get that simply by enabling exactOptionalPropertyTypes. https://www.typescriptlang.org/tsconfig#exactOptionalPropertyTypes
exactOptionalPropertyTypes
This issue has been marked as "Question" and has seen no recent activity. It has been automatically closed for house-keeping purposes.
No branches or pull requests
π Search Terms
.
π Version & Regression Information
.
β― Playground Link
https://www.typescriptlang.org/play?#code/C4TwDgpgBAsiAq5oF4BQUNQD5QN5QDsBDAWwgC4oBnYAJwEsCBzKAX3Ux32LMpoeYBuKAHswweiOIAbSnQCu0dqgDGUmlBIgAakWmKoyPBww8KUAEQWANCdHjJMyvIIATCADNGEV9agB6fygAdQB5ACUAaQBlPwAhAFV4KABJKABRAA0ABXSAYWSU5PhQjPDwiNR2IA
π» Code
π Actual behavior
π Expected behavior
Additional information about the issue
I don't know if this should be a bug report or a feature request.
The text was updated successfully, but these errors were encountered: