如何解决在本地机器 (MERN) 中部署 Express.js 和 Typescript 项目 - TSError: ⨯ 无法编译 TypeScript
我在另一台服务器上部署已经运行的项目时遇到这些错误。但是在部署我的本地机器时,我收到了这些错误。我尝试了很多可能的场景,但都没有解决。
我尝试再次安装 node_modules 和 npm update cmd。并尝试了许多其他解决方案,例如 tsconfig.json 文件和其他升级版本和降级版本中的一些更改。但出现错误。
TSError: ⨯ Unable to compile TypeScript:
src/services/UserService/UserService.ts:103:26 - error TS2345: Argument of type 'IUser' is not assignable to parameter of type '_FilterQuery<_AllowStringsForIds<Pick<_LeanDocument<IUser>,string | number>>>'.
Type 'IUser' is not assignable to type 'RootQuerySelector<_AllowStringsForIds<Pick<_LeanDocument<IUser>,string | number>>>'.
Types of property '$where' are incompatible.
Type 'Record<string,unkNown>' is not assignable to type 'string | Function | undefined'.
Type 'Record<string,unkNown>' is not assignable to type 'string'.
103 return User.findOne(user).then(addNotificationsTimezone);
src/services/UserService/UserService.ts:195:13 - error TS2740: Type 'Pick<_LeanDocument<IUser>,string | number>' is missing the following properties from type 'IUser': id,isConnectedFitbit,garminToken,garminTokenSecret,and 75 more.
195 const objUser: IUser = user.toObject()
我的 Package.json 文件
{
"name": "lean-cuisine-server","version": "1.0.0","description": "","main": "app.js","scripts": {
"start": "node ./dist/src/server/server.js","start:watch": "node -r ts-node/register ./src/server/server.ts","start:debug": "nodemon --inspect=5858 -r ts-node/register ./src/server/server.ts","dev": "nodemon --legacy-watch","doc": "apidoc -i ./src/controllers/ -o ./docs && npm run rm-docs && npm run cp-docs","rm-docs": "aws --profile appspeople s3 rm --recursive s3://lean-cuisine-docs-api","cp-docs": "aws --profile appspeople s3 cp --recursive --acl public-read ./docs s3://lean-cuisine-docs-api","build": "tsc","test": "SET NODE_ENV=test&& ts-mocha --inspect=5858 -p ./tsconfig.json '__tests__/**/**/*.test.ts'","test:coverage": "SET NODE_ENV=test&& nyc ts-mocha --inspect=5858 -p ./tsconfig.json '__tests__/**/**/*.test.ts'"
},"author": "Vitor Sachini","license": "ISC","dependencies": {
"awilix": "^4.2.6","aws-sdk": "^2.771.0","axios": "^0.21.1","bcryptjs": "^2.4.3","cookie-parser": "^1.4.5","cors": "^2.8.5","dotenv": "^8.2.0","express": "^4.17.1","firebase-admin": "^9.2.0","fitbit-node": "^2.2.0","googleapis": "^58.0.0","helmet": "^4.1.1","http-status": "^1.4.2","jsonwebtoken": "^8.5.1","moment": "^2.29.1","mongoose": "^5.10.9","morgan": "^1.10.0","node-cron": "^2.0.3","nodemailer": "^6.4.13","oauth-1.0a": "^2.2.6","reflect-Metadata": "^0.1.13","simple-express-route-builder": "^0.1.1","striptags": "^3.1.1","winston": "^3.3.3"
},"devDependencies": {
"@types/bcryptjs": "^2.4.2","@types/bluebird": "^3.5.32","@types/chai": "^4.2.13","@types/cookie-parser": "^1.4.2","@types/cors": "^2.8.8","@types/express": "^4.17.8","@types/jsonwebtoken": "^8.5.0","@types/mongoose": "^5.7.36","@types/morgan": "^1.9.1","@types/node": "^14.11.8","@types/node-cron": "^2.0.3","@types/nodemailer": "^6.4.0","@types/sinon": "^9.0.8","@types/sinon-chai": "^3.2.5","@types/sinon-express-mock": "^1.3.9","@types/validator": "^13.1.0","@typescript-eslint/eslint-plugin": "^3.10.1","@typescript-eslint/parser": "^3.10.1","apidoc": "^0.23.0","chai": "^4.2.0","eslint": "^7.11.0","eslint-plugin-jsdoc": "^27.1.2","eslint-plugin-prefer-arrow": "^1.2.2","mocha": "^8.1.3","nodemon": "^2.0.5","nyc": "^15.1.0","sinon": "^9.2.0","sinon-chai": "^3.5.0","sinon-express-mock": "^2.2.1","ts-mocha": "^7.0.0","ts-node": "^8.10.2","typescript": "^3.9.6"
},"apidoc": {
"name": "Lean Cuisine API","description": "API Powering Lean Cuisine.","title": "Lean Cuisine API Documentation","url": "http://lean-cuisine-docs-api.s3-website-ap-southeast-2.amazonaws.com/api"
},"nodemonConfig": {
"ignore": [
"**/*.test.ts","**/*.spec.ts",".git","node_modules"
],"watch": [
"src/","app.ts"
],"exec": "npm run start:watch","ext": "ts"
}
}
{
"compilerOptions": {
"target": "es6","module": "commonjs","noEmitOnError": true,"sourceMap": true,"outDir": "dist","strict": true,"noImplicitAny": false,"jsx": "react","noUnusedLocals": true,"noUnusedParameters": true,"moduleResolution": "node","typeRoots": [
"./src/types","./node_modules/@types"
],"esModuleInterop": true,"experimentalDecorators": true,"emitDecoratorMetadata": true,"skipLibCheck": true,"forceConsistentCasingInFileNames": true,"resolveJsonModule": true,"lib": [
"esnext"
]
},}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。