當我嘗試將 Objection.js 模型注入 NestJs 服務時:
constructor(@Inject('UserModel') private readonly modelClass: ModelClass<UserModel>) {}
我Maximum call stack size exceeded在編譯時遇到錯誤。我認為這是由于我的其他模型和一些回圈依賴。我洗掉了單個模型之外的所有內容,但仍然出現例外。
如果我"strict": true在 tsconfig.json 中設定,代碼會按預期構建和運行。我該如何補救這種情況?
以下是使用的模型和包。
基礎模型
export default class BaseModel extends Model {
readonly id: number;
createdBy: number;
created!: string;
modified: string;
modifiedBy: number;
}
用戶模型
export default class UserModel extends BaseModel {
static tableName = 'users';
static virtualAttributes = ['fullName'];
firstName!: string;
lastName!: string;
company?: string;
email!: string;
fullName(): string {
return `${this.firstName} ${this.lastName}`;
}
static jsonSchema = {
type: 'object',
required: ['firstName', 'lastName', 'email'],
properties: {
id: { type: 'number' },
firstName: { type: 'string' },
lastName: { type: 'string' },
company: { type: 'string' },
email: { type: 'string' },
},
};
}
套餐:
"dependencies": {
"@apollo/gateway": "^0.44.0",
"@nestjs/common": "^8.2.1",
"@nestjs/core": "^8.2.1",
"@nestjs/graphql": "^9.1.1",
"@nestjs/platform-express": "^8.0.0",
"ajv-formats": "^2.1.1",
"apollo-server-express": "^3.5.0",
"class-transformer": "^0.4.0",
"class-validator": "^0.13.1",
"dayjs": "^1.10.7",
"dotenv": "^10.0.0",
"graphql-subscriptions": "^2.0.0",
"knex": "^0.95.14",
"objection": "^3.0.0",
"pg": "^8.7.1",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"rxjs": "^7.4.0"
},
"devDependencies": {
"@nestjs/cli": "^8.0.0",
"@nestjs/schematics": "^8.0.0",
"@nestjs/testing": "^8.0.0",
"@types/express": "^4.17.13",
"@types/jest": "^27.0.1",
"@types/node": "^16.0.0",
"@types/supertest": "^2.0.11",
"@typescript-eslint/eslint-plugin": "^5.0.0",
"@typescript-eslint/parser": "^5.0.0",
"eslint": "^8.0.1",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "2.25.2",
"eslint-plugin-prettier": "^4.0.0",
"jest": "^27.2.5",
"prettier": "^2.3.2",
"source-map-support": "^0.5.20",
"supertest": "^6.1.3",
"ts-jest": "^27.0.3",
"ts-loader": "^9.2.3",
"ts-morph": "^12.2.0",
"ts-node": "^10.0.0",
"tsconfig-paths": "^3.10.1",
"typescript": "^4.4.2"
},
uj5u.com熱心網友回復:
根據這個問題,打字稿必須在strict模式下運行才能正確地轉換代碼。似乎反對 v3 仍處于某種預發布狀態,所以這還沒有完全記錄。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/364722.html
標籤:节点.js 新产品经理 嵌套 knex.js 反对意见.js
