-
Notifications
You must be signed in to change notification settings - Fork 642
Description
import { Model, RelationMappings, RelationMappingsThunk } from 'objection';
export class BaseModel extends Model {
id: number;
static get modelPaths() {
return [__dirname];
}
}
export class Product extends BaseModel {
static tableName = 'product';
price: number;
user?: User;
static relationMappings: RelationMappings | RelationMappingsThunk = {
productList: {
relation: Model.BelongsToOneRelation,
modelClass: 'User',
join: {
from: 'product.userId',
to: 'user.id',
},
},
};
}
export class User extends BaseModel {
static tableName = 'user';
name: string;
// productList?: Product;
static relationMappings: RelationMappings | RelationMappingsThunk = {
productList: {
relation: Model.HasManyRelation,
modelClass: 'Product',
join: {
from: 'user.id',
to: 'product.userId',
},
},
};
}
If I uncomment the line "productList?: Product", I got the following error:
RangeError: Maximum call stack size exceeded
at recursiveTypeRelatedTo (/Applications/MAMP/htdocs/test-obj3/node_modules/typescript/lib/typescript.js:63793:44)
at isRelatedTo (/Applications/MAMP/htdocs/test-obj3/node_modules/typescript/lib/typescript.js:63388:30)
at typeRelatedToSomeType (/Applications/MAMP/htdocs/test-obj3/node_modules/typescript/lib/typescript.js:63654:35)
at structuredTypeRelatedToWorker (/Applications/MAMP/htdocs/test-obj3/node_modules/typescript/lib/typescript.js:63926:32)
at structuredTypeRelatedTo (/Applications/MAMP/htdocs/test-obj3/node_modules/typescript/lib/typescript.js:63908:30)
at isRelatedTo (/Applications/MAMP/htdocs/test-obj3/node_modules/typescript/lib/typescript.js:63385:30)
at checkTypeRelatedTo (/Applications/MAMP/htdocs/test-obj3/node_modules/typescript/lib/typescript.js:63003:26)
at isTypeRelatedTo (/Applications/MAMP/htdocs/test-obj3/node_modules/typescript/lib/typescript.js:62954:24)
at isTypeAssignableTo (/Applications/MAMP/htdocs/test-obj3/node_modules/typescript/lib/typescript.js:62160:20)
at getConditionalType (/Applications/MAMP/htdocs/test-obj3/node_modules/typescript/lib/typescript.js:60943:133)
This only happens after upgrading to [email protected]. This is fine in 2.x.
Already set tsconfig to
"strict": true,
Seems related to
microsoft/TypeScript#33460