-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Removing 'optional' attributes from a type's properties disallow adding undefined as it's type #46850
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
Sounds like a duplicate of #31025. |
I don't see any repro here that demonstrates what you're talking about. Please provide an minimal/actionable sample that clearly demonstrates what you consider to be the bug |
Hi @RyanCavanaugh, Hover over BadNullableTest in the playground, you'll see that previously optional attributes are defined as Regards, |
Please provide an minimal/actionable sample that clearly demonstrates what you consider to be the bug, not a textual description of where to look in a long sample |
@KuSh does the relatively new compiler option type NullableType<T> = {
[K in keyof T]-?: undefined extends T[K]
? T[K] | null | undefined
: T[K]
}
type Test = {
req: string
opt?: string
canBeNull: string | undefined
}
type EQ = NullableType<Test>
// ^?
const shouldPass: EQ = {req: "", opt: undefined, canBeNull: undefined} |
It seems so. But is effectively too recent for my current project (which use TS 4.3) and also has other consequencies as we're used to set optional props as undefined (outside of NullableTypes). Thanks for tip I'll keep that in mind π |
This issue has been marked as 'Unactionable' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
Uh oh!
There was an error while loading. Please reload this page.
Bug Report
π Search Terms
type generic remove optional attribute
π Version & Regression Information
I did test this on 4.4.4 and 4.5.0-beta using playground
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
Removing optional attribute from type also remove undefined from final type
(when not removing optional attribute, final type is x?: typeof x | null | undefined)
π Expected behavior
Removing optional attribute just removes the optional attribute and doesn't modify final type
The text was updated successfully, but these errors were encountered: