You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
typeTestType={optionalField?: string;presenceRequiredButCanBeUndefined: number|undefined;required: boolean}typeAlwaysStringOrUndefined<T>={[KeyinkeyofRequired<T>]: string|undefined;};typeT1=AlwaysStringOrUndefined<TestType>// ^?// ^ optionalField has just `string`, no undefinedtypeAlwaysStringOrUndefinedOrNull<T>={[KeyinkeyofRequired<T>]: string|undefined|null;};typeT1b=AlwaysStringOrUndefined<TestType>// ^?// ^ optionalField has just `string`, no undefinedtypeWithAllFieldsExplicit<T>={[KeyinkeyofRequired<T>]: Omit<T,Key>extendsT ? T[Key]|null : T[Key];};typeT2=WithAllFieldsExplicit<TestType>;// ^?// Here it works if you add "| null", then the undefined appears again... If you just do `| undefined` it gets swallowed
π Actual behavior
The | undefined gets swallowed from mapped types when mapping from a type with optional fields which are removed through Required<T> or through -?
π Expected behavior
The undefined should not be swallowed. Especially not when using keyof Required<T> instead of -?
Additional information about the issue
No response
The text was updated successfully, but these errors were encountered:
π Search Terms
swallows undefined -? mapped types
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play/?ts=5.7.0-beta&ssl=15&ssc=1&pln=17&pc=1#code/C4TwDgpgBAKhDOwbmgXigbygezMAltgHYCGANgGL4RkAmA-AFxSIBO+RA5gNxRisIIRAMYQAShACOAV3wDaAIWnAAwiSIKIAVSK0IAMw4RazItIC2AIwisoAHyjTdBo7V4CZc480vZsZCHUoAF8AKFDQSCgAQTIAdxIQeABlYHYuAHlWHT1DImMAHhgAPih0DFCoKABtAGkIECgOKABrBux9KAlPeSLigF1mNg5Oe0dnPONuUODpyOgYAEYymPjElLSRrJyXfNoihCQUYtCAelOqqAA9ejOLq5w8QlJKajooAAsSeCgAK2lEFAAAbDLhAgA0UCI2HGuVc4XmqwSSVS6U42wmriyADlpGQyH0VhUqnUGk0iK12p1urJeiVBixNlwxk44XsxmZ8dNZhEULBFpYVrFkRs0Ri2YU4IhkJATudLjc7tdHgRiOQqDRaJ9vn8AcBgaDOBCoTDWbtjOFeVEAOr4YAfWKvTXwACiAA8wGR8MI7YTypUavVGs02iAOl0pLTJQNmBlzL6YJCg6UIG7gEJaD8YFB6LBSSB+hy8WQoMwYPn+ty5nyYAAmFa2+2OjV0V0er0+4AHaXHabyqqK+UACRs0DtUDi2FYLR++E6YekUBItC1ACIHJyyKvIfahFBd7DzVqSGBICRWD8SJwSBwAHT3oA
π» Code
π Actual behavior
The
| undefined
gets swallowed from mapped types when mapping from a type with optional fields which are removed throughRequired<T>
or through-?
π Expected behavior
The undefined should not be swallowed. Especially not when using
keyof Required<T>
instead of-?
Additional information about the issue
No response
The text was updated successfully, but these errors were encountered: