myzod
myzod copied to clipboard
Fails to compile with TS 4.7.2
After upgrading typescript, I get the following compilation error
node_modules/myzod/libs/types.d.ts:256:40 - error TS2577: Return type annotation circularly references itself.
256 and<K extends AnyType>(schema: K): IntersectionResult<this, K>;
~~~~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/myzod/libs/types.d.ts:306:40 - error TS2577: Return type annotation circularly references itself.
306 and<K extends AnyType>(schema: K): IntersectionResult<this, K>;
I'm getting errors on Typescript 4.7.2 as well, but slightly different ones:
src/types.ts:58:22 - error TS2589: Type instantiation is excessively deep and possibly infinite.
58 export type Result = Infer<typeof resultSchema>;
~~~~~~~~~~~~~~~~~~~~~~~~~~
src/types.ts:58:22 - error TS2590: Expression produces a union type that is too complex to represent.
58 export type Result = Infer<typeof resultSchema>;
~~~~~~~~~~~~~~~~~~~~~~~~~~
I will try and investigate in the next week or so. Hopefully it will be simple enough to fix but when when tsc changes their depth heuristics it can be challenging.
Any news on this?
Using typescript 4.7.4 the error disappear when I set strict: true in tsconfig.json. Cant find any reason why.
I get the same errors with TS 4.7.4 with strict: true
. Line 256 and 306. Node v14.19.0.
Any updates on this? TS 4.8.X is now out.
Doesn't seem to fix the problem unfortunately. Typescript has changed its heuristics such that the Intersection type is now deemed to circularly reference itself.
Unfortunately I do not foresee time to play around and fix this, so it will have to come from the community if at all, but it is not an easy problem to solve...
Is it worth maybe filing a ticket against the Typescript repo to see if it was a bug on their side in the heuristics algorithm that they'd be willing to address?
Looks like this issue should be resolved when TypeScript 4.9 releases
@DavidRigglemanININ Thanks for following this closely. Can you link to what makes you suspect TS4.9 will fix this?
@DavidRigglemanININ Thanks for following this closely. Can you link to what makes you suspect TS4.9 will fix this?
I had created an issue with the TypeScript project and fortunately someone else was able to create a sample project that showed a similar typing regression that started in the same version that I reported. And if you look at the linked issue above, a fix was made and it appears targeted by 4.9
Unfortunately, while 4.9.4 does fix the originally reported error, now I'm getting a new error:
node_modules/myzod/libs/types.d.ts:51:136 - error TS2589: Type instantiation is excessively deep and possibly infinite.
51 export declare type IntersectionResult<T extends AnyType, K extends AnyType> = T extends ObjectType<any> ? K extends ObjectType<any> ? ObjectIntersection<T, K> : IntersectionType<T, K> : T extends ArrayType<any> ? K extends ArrayType<any> ? ArrayIntersection<T, K> : IntersectionType<T, K> : T extends TupleType<any> ? K extends TupleType<any> ? TupleIntersection<T, K> : IntersectionType<T, K> : T extends MTypeClass<any, any> ? never : K extends MTypeClass<any, any> ? never : IntersectionType<T, K>;
I've updated the ticket in the TypeScript project and will report back if I get any helpful info
I've create a merge pull request (https://github.com/davidmdm/myzod/pull/58). Could you check this please ?
@Nicolas469 It has been merged!
@DavidRigglemanININ, please confirm that updated to version 1.9.0 fixes your issues and I will close this issue
Sadly no. I'll make another one soon.
@Nicolas469 I am not seeing any errors on my end compiling and running tests, nor playing around with it. What are you experiencing? I have also updated typescript to latest.
I've got an express backend using this as depedency. When running in dev mode (with ts-node-dev) no problem. But if I run tsc to compile the code into javascript, I've got:
#11 12.48 node_modules/myzod/libs/types.d.ts(48,159): error TS2589: Type instantiation is excessively deep and possibly infinite. #11 12.48 node_modules/myzod/libs/types.d.ts(51,128): error TS2589: Type instantiation is excessively deep and possibly infinite.
@Nicolas469 What version of typescript are you using? I am trying to reproduce but it works fine for me using typescript 4.9.5
Also version 4.9.5. The build is working but if you go in the libs folder and check the types.d.ts file, you'll see the errors on lines 48 and 51.
It still fails for me on 4.9.5
node_modules/myzod/libs/types.d.ts:48:159 - error TS2589: Type instantiation is excessively deep and possibly infinite.
48 type ObjectIntersection<O1 extends ObjectType
node_modules/myzod/libs/types.d.ts:51:128 - error TS2589: Type instantiation is excessively deep and possibly infinite.
51 export type IntersectionResult<T extends AnyType, K extends AnyType> = T extends ObjectType
@DavidRigglemanININ please check my last pull request.
What's the updated library version to use?
@DavidRigglemanININ and @Nicolas469 try version 1.9.2
I seem to be having success...
If you two can replicate it this issue is closed and myzod is unblocked for new typescript versions!
Looks ok for me :)
Its working for me now. Thanks!
Closing for now!
Tremendous shoutout to @Nicolas469 for resolving this issue. I have not had the time to work on this for the past year so this is incredible.
🎉 🎉 🎉
Are there any implications to this change? In other words, what are we losing? Will some consumers of this library now no longer get type checking, leading to potentially invalid types being used but not checked? Or is this strictly internal type checking within the library. It might not be a bad idea to revisit every once in a while with new TypeScript releases if the ignores can be removed.
I am seeing this error with myzod v1.11.0, Typescript v5.5.4, and Node v22.4.1.
node_modules/.pnpm/[email protected]/node_modules/myzod/libs/types.d.ts:49:146 - error TS2589: Type instantiation is excessively deep and possibly infinite.
49 type ArrayIntersection<A1 extends ArrayType<any>, A2 extends ArrayType<any>> = A1 extends ArrayType<infer S1> ? A2 extends ArrayType<infer S2> ? ArrayType<IntersectionResult<S1, S2>> : never : never;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Found 1 error in node_modules/.pnpm/[email protected]/node_modules/myzod/libs/types.d.ts:49
This error goes away when I downgrade to Typescript v5.3.3 maintaining same versions of myzod (v1.11.0) and Node (v22.4.1).