-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
[tsc] Regression causing 'Maximum call stack size exceeded' #33460
Comments
Maybe related: #32582 |
Running with 3.6.3 the error has changed a bit...
|
Version 3.7.0-dev.20190917
|
This also happens with objection.js typings. I don't know if this helps, but you can reproduce it like this:
Using the package.json version
I was able to find out that this monstrosity of a type is the culprit: |
Oh, the original reproduction was also done using objection typings 😄 |
@koskimas I'm also sorry to say that I've now moved on from Objection to MikroORM. =( |
I just found out that changing this type GraphParameters = {
'#dbRef'?: MaybeCompositeId;
'#ref'?: string;
'#id'?: string;
};
type PartialModelGraph<T> = {
[K in NonFunctionPropertyNames<T>]?: Exclude<T[K], undefined> extends Model
? PartialModelGraph<Exclude<T[K], undefined>>
: Exclude<T[K], undefined> extends Array<infer I>
? (I extends Model ? PartialModelGraph<I>[] : (T[K] | NonPrimitiveValue))
: (T[K] | NonPrimitiveValue);
} &
GraphParameters; into this type GraphParameters = {
'#dbRef'?: MaybeCompositeId;
'#ref'?: string;
'#id'?: string;
};
type PartialModelGraph<M, T = M & GraphParameters> = {
[K in NonFunctionPropertyNames<T>]?: Exclude<T[K], undefined> extends Model
? PartialModelGraph<Exclude<T[K], undefined>>
: Exclude<T[K], undefined> extends Array<infer I>
? (I extends Model ? PartialModelGraph<I>[] : (T[K] | NonPrimitiveValue))
: (T[K] | NonPrimitiveValue);
} fixes the problem. Also note that @lookfirst's reproduction uses objection 1.6.9 while the above types and my repro is with objection 2.0 typings which have been completely rewritten from scratch. So this fix only applies to my repro. |
I just ran into the same problem on v3.7.2
The problem appeared when using "morphism" together with "sequelize" and I managed to reproduce it with this: function morphism<TSchema = Schema<DestinationFromSchema<Schema>, SourceFromSchema<Schema>>, Source extends SourceFromSchema<TSchema> = SourceFromSchema<TSchema>>(schema: TSchema, data: Source[]): DestinationFromSchema<TSchema>[] {
throw new Error();
}
type SourceFromSchema<T> = T extends Schema<unknown, infer U> ? U : never;
type DestinationFromSchema<T> = T extends Schema<infer U> ? U : never;
declare const SCHEMA_OPTIONS_SYMBOL: unique symbol;
type Schema<Target = any, Source = any> = {
[destinationProperty in keyof Target]?: Schema<Target[destinationProperty], Source>;
} & {
[SCHEMA_OPTIONS_SYMBOL]?: any;
};
export class Sequelize {
public Sequelize!: typeof Sequelize;
}
interface MyModel extends Sequelize {
vehicleId: string;
}
export interface MyModelDTO {
id: string;
}
export const MyModelDTOVehicleModel: Schema<MyModel, MyModelDTO> = {
vehicleId: 'id',
};
const output: MyModel[] = morphism(MyModelDTOVehicleModel, [{
id: 'ID',
}]); As mentioned before it works in version 3.5.3. |
Just use MikroORM v3, seriously. |
Spent this morning looking into this:
The loop seems to roughly be (based on
I've not been able to replicate this in a baseline yet Current baseline WIP
|
@orta I used the included test project and confirmed it no longer errors in |
Still "Maximum call stack size exceeded" with objection |
@xtance It was fine for a long time there. It's a new issue, not necessarily related to this one. Adding |
I also got the "Maximum call stack size exceeded" using Objection on version 3.0.0 and Typescript on version 4.4.4. |
Same error occured to me, I tried updating typescript to 4.5.2 but it didn't help. My objection version is 3.0.0 and knex version is 0.95.14 |
This error is produced also in latest build. I reach it finally too. I thing its about toobig projects. But where is the limit? |
Hopefully this one can get fixed quickly since it is a pretty major regression. I spent a lot of time figuring out exactly which version range is causing the failure as well as trying to figure out a minimal test case.
TypeScript Version:
Failure at version:
3.6.0-dev.20190807
and above.Everything works:
3.6.0-dev.20190806
and lower.Code
tsc-fail.zip
To run:
Expected behavior:
No error.
Actual behavior:
The text was updated successfully, but these errors were encountered: