-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Inconsistent behaviour of -?
#59948
Comments
I think TS is tripping balls and hallucinating here. Both type Res1a = Res1['a']; // string | undefined
let r: Res1 = {a: undefined}; // Ok
type Id<T extends object> = {[K in (keyof T & string)]: T[K]};
type Res1Id = Id<Res1>; // { a: string | undefined } This issue might be related to the |
There's no |
The |
I think this is just a type display issue. If you actually access the property, it has the expected type: type OptionalToUnionWithUndefined<T> = {
[K in keyof T]: T extends Record<K, T[K]>
? T[K]
: T[K] | undefined
}
type Intermidiate = OptionalToUnionWithUndefined<{ a?: string }> // { a?: string | undefined }
type M = { a?: string }
type Literal = { a?: string | undefined } // same type as Intermidiate
type Res1 = Required<Intermidiate> // { a: string }
type Res2 = Required<Literal> // { a: string | undefined }
declare let r: Res1;
const j = r.a;
// j: string | undefined
// OK
const p: Res2['a'] = undefined; |
π Search Terms
optional mapped type
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play/?exactOptionalPropertyTypes=true#code/C4TwDgpgBA8mwEsD2A7AhgGwCpIKouRQHUFgALfAEwgDMEUJKAeLAPigF4oBvAKCgFQA2gGko9KAGsIIJDShYAugC4FUCAA9gEFJQDOUAEoQAxkgBOzEQBoFoxa36DnAfjsjFT5wNVZ7UAB8oAFddWnpGXgBfXl5QSCgASRRtcwBbBEoENG1OWHhCTBx8QhJyKnCGZm4oNBdVPWBzegBzKCj2AHpOnlr6qEbmlDag0Oo6Kva48GgAGVIIc0w8mrqGptbAkLCJxnaoboG0NOh46DQDZNSMrJyIWLOjCD0ARjzjAEdghHNGJivFjdstouj1Vushm0Yo9jHoAEzvCBfH5-eapTCg3poCGbUY7CKUdpAA
π» Code
π Actual behavior
Res1
andRes2
are different typesπ Expected behavior
they should be the same because the inputs are
Additional information about the issue
This issue may share the cause with #59902
The text was updated successfully, but these errors were encountered: