-
Notifications
You must be signed in to change notification settings - Fork 12.8k
typesafe-joi blows up TypeScript 3.2+ #28873
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
Comments
Without npx using command
Running node setting a stack-trace-limit to 100000 (to see the full stack trace) with Seems that the recursion starts at call to
|
The issue here is that interface AbstractSchema<Schema extends AbstractSchema = any, Value = any> extends JoiObject { ... } The use of default type arguments in combination with the recursive constraint causes an infinite loop. An easy fix for now is to specify the type arguments: interface AbstractSchema<Schema extends AbstractSchema<any, any> = any, Value = any> extends JoiObject { ... } |
@weswigham Best I can tell the infinite loop is caused by |
@ahejlsberg I assume TypeScript will fill in the type arguments automatically, because |
I made local fix, you can try to apply and see if it helps |
@EvgenyMuryshkin Doh! You're right, it definitely should be calling |
@weswigham @rbuckton @DanielRosenwasser I'm thinking that all of the proposed solutions to this issue paper over the the real culprit: Type parameter defaults should only be allowed to reference previously declared type parameters (i.e. type parameters declared to the left). I alluded to this in my comment here. Such a rule would be analogous to JavaScript's restriction that parameter defaults can only reference parameters to the left, and it would make nonsensical constructs such as the following become errors: type Foo<T = T> = T[];
type Bar<T = U, U = T> = [T, U]; After all, when a type parameter default comes into play, we know that type arguments for that type parameter and type parameters to the right of it weren't specified, so there is nothing meaningful to reference. The OP issue is caused by us trying to come up with a meaningful default for a forward reference (and our answer effectively amounts to the constraint of the forwardly referenced type parameter), but I'm thinking it should just be an error (and we should just use the error type). I suppose you could make a weak argument that type parameter defaults in generic functions should be able to reference later type parameters because type inference might produce useful inferred types, but I have yet to see a real world example where that is useful. I have a branch that implements this restriction and I'm the process of running validating all of Definitely Typed on it. So far nothing seems to be affected. |
We are using this project and I had to tweak type definition a bit after 3.2 migration https://github.com/projectstorm/react-diagrams/blob/master/src/BaseEntity.ts |
Hey guys, typesafe-joi make typescript crash again in #30794. Please help! |
TypeScript Version: 3.3.0-dev.20181205
Search Terms:
Maximum call stack size exceeded
Code Repo:
https://github.com/hjkcai/typesafe-joi
Reproduction:
Expected behavior:
tsc should work.
I admit that typesafe-joi uses lots of type recursion, but it works fine in TypeScript 3.1. After upgrading to TypeScript 3.2, the error comes.
Actual behavior:
tsc itself encountered 'Maximum call stack size exceeded' (No stack trace printed)
The text was updated successfully, but these errors were encountered: