🔎 Search Terms
"typescript 5.7", "type assertions", "casting", "regression", "zod", "tsc"
🕗 Version & Regression Information
- This changed between versions 5.6.3 and 5.7.2
⏯ Playground Link
https://www.typescriptlang.org/play/?ts=5.7.2#code/C4TwDgpgBA6gTgQzJOAeAKgPigXigbwCgoSoB9USALinUIF9DCAzAVwDsBjYASwHt2UAM7A4PdgHN4SFAAoAlDWnIIaEWMnYipKHAjBWcQfnKUINAEQWojRiw7d+gvgCMAVspQYoEAB7AIdgATISgAJQhOPjgg1HVxCQAaWEQVNAR2EExs2Vc3GnRFFJlVDC1iUj0DIwJTcHMoPJsGJij2ESgANwQAG1ZoPDzPVVltUjA4PjAARhp4yWG4BSgEUMXUCwALCB6evgtMBnkmMygAVXYAd1TvPwDgtdSvDKzsPHQAbQByCnqvgF0fP5AiFwpForF5klimlUC9slAKiQAPy1D4AaQgICg4igAGssXxmLRvr9IAD-jQLtckBhSWYARisf9sPREToCvS-v8TvVaBAOnhqTczESur1+ocAPRS0gAPWRQA
💻 Code
typeWrapper<T>={_type: T}functionstringWrapper(): Wrapper<string>{return{_type: ""}}functionobjWrapper<TextendsRecord<string,Wrapper<any>>>(obj: T): Wrapper<T>{return{_type: obj}}constvalue=objWrapper({prop1: stringWrapper()asWrapper<"hello">})typeUnwrap<TextendsWrapper<any>>=T['_type']extendsRecord<string,Wrapper<any>> ? {[KeyinkeyofT['_type']]: Unwrap<T['_type'][Key]>} : T['_type']typeTest=Unwrap<typeofvalue>🙁 Actual behavior
The type of Test is { prop1: Wrapper<"hello">; } in v5.7.
This is wrong because the Unwrap type should recursively extract the underlying type of each Wrapper.
🙂 Expected behavior
The type of Test should be { prop1: "hello"; }, like it is in v5.6.
Additional information about the issue
This issue seems related to the inline type assertion on line 14. The inference is corrected if the type assertion happens on a separate line, such as:
conststrWrapper=stringWrapper()asWrapper<"hello">;constvalue=objWrapper({prop1: strWrapper});typeTest=Unwrap<typeofvalue>// ^? type Test = { prop1: "hello"; }This is a simplified version of an issue I'm seeing with some Zod schemas after upgrading to TypeScript 5.7.
🔎 Search Terms
"typescript 5.7", "type assertions", "casting", "regression", "zod", "tsc"
🕗 Version & Regression Information
⏯ Playground Link
https://www.typescriptlang.org/play/?ts=5.7.2#code/C4TwDgpgBA6gTgQzJOAeAKgPigXigbwCgoSoB9USALinUIF9DCAzAVwDsBjYASwHt2UAM7A4PdgHN4SFAAoAlDWnIIaEWMnYipKHAjBWcQfnKUINAEQWojRiw7d+gvgCMAVspQYoEAB7AIdgATISgAJQhOPjgg1HVxCQAaWEQVNAR2EExs2Vc3GnRFFJlVDC1iUj0DIwJTcHMoPJsGJij2ESgANwQAG1ZoPDzPVVltUjA4PjAARhp4yWG4BSgEUMXUCwALCB6evgtMBnkmMygAVXYAd1TvPwDgtdSvDKzsPHQAbQByCnqvgF0fP5AiFwpForF5klimlUC9slAKiQAPy1D4AaQgICg4igAGssXxmLRvr9IAD-jQLtckBhSWYARisf9sPREToCvS-v8TvVaBAOnhqTczESur1+ocAPRS0gAPWRQA
💻 Code
🙁 Actual behavior
The type of
Testis{ prop1: Wrapper<"hello">; }in v5.7.This is wrong because the
Unwraptype should recursively extract the underlying type of eachWrapper.🙂 Expected behavior
The type of
Testshould be{ prop1: "hello"; }, like it is in v5.6.Additional information about the issue
This issue seems related to the inline type assertion on line 14. The inference is corrected if the type assertion happens on a separate line, such as:
This is a simplified version of an issue I'm seeing with some Zod schemas after upgrading to TypeScript 5.7.