-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Type assertion regression in TypeScript 5.7 #60573
Comments
This ia display-only bug introduced by #59282 . For type printing purposes it reuses here the assertion type but it misses the fact that this type can be processed by the template of a mapped type. How do we know it's just a display-only bug? Just inspect this: type Test2 = Unwrap<typeof value>["prop1"]
// ^? type Test2 = "hello" |
You're right that my minimal reproduction is a display-only bug. But in a larger codebase, I am seeing a very similar example break type-inference and checking for a Zod schema. What's weirder is that the larger example displays correctly in my IDE, but only errors when running I will try to refine my reproduction above to see if I can produce the type-checking regression. |
It would be appreciated because it should be a completely different bug. Fixing this display-only bug is just very unlikely to fix what you are describing above. |
@Andarist I haven't yet been able to reproduce the issue without using Zod, but here is a simplified example of the problem with Zod:
It seems like the problem also somehow relates to using |
Ah, well - so this is actually the same issue. A type display issue like this is a type serialization issue after all and that affects emitted declaration files too (and that's what happens in your repro above). My fix should cover this already, I'll consider adding some extra tests for this too |
π 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
Test
is{Β prop1:Β Wrapper<"hello">;Β }
in v5.7.This is wrong because the
Unwrap
type should recursively extract the underlying type of eachWrapper
.π 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:
This is a simplified version of an issue I'm seeing with some Zod schemas after upgrading to TypeScript 5.7.
The text was updated successfully, but these errors were encountered: