Javascript 类型MyClass:Typescript上不存在属性myProp
我有一个简单的Typescript类Javascript 类型MyClass:Typescript上不存在属性myProp,javascript,node.js,typescript,api,types,Javascript,Node.js,Typescript,Api,Types,我有一个简单的Typescript类 export class UserController { constructor(private service: UserService) { } async insert(req, res: Response) { } } 该类在一个文件index.ts中声明如下 import { UserService } from "./UserServic
export class UserController {
constructor(private service: UserService) {
}
async insert(req, res: Response) {
}
}
该类在一个文件index.ts中声明如下
import { UserService } from "./UserService";
import { UserController } from "./UserController";
const service = new UserService()
const userController = new UserController(service)
export {userController}
这就是控制台上的错误:
使用ts节点版本8.10.2,typescript版本3.9.7[错误]
10:37:49 ⨯ 无法编译类型脚本:
src/useCases/User/UserController.ts:6:14-错误TS2339:Property
类型“UserController”上不存在“服务”
this.service = service;
如果它们很重要,那就是我的tsconfig.json和package.json
{
"compilerOptions": {
"target": "ES2017",
"module": "commonjs",
"lib": [
"es6"
],
"allowJs": true,
"outDir": "./dist",
"rootDir": "./src",
"removeComments": true,
"strict": false,
"typeRoots": [
"./node_modules/@types",
"./src/@types"
],
"esModuleInterop": true,
"resolveJsonModule": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"baseUrl": ".",
"paths": {
"@controllers/*": [
"./src/controllers/*"
],
"@entities/*": [
"src/entities/*"
],
"@config/*": ["src/config/*"],
"@repositories/*": ["src/repositories/*"],
"@useCases/*": ["src/useCases/*"],
"@utils/*": ["src/utils/*"]
}
},
"include": [
"./src/**/*"
]
}
{
"name": "area-do-cliente",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"scripts": {
"dev": "ts-node-dev -r tsconfig-paths/register --respawn --transpile-only --ignore-watch node_modules --no-notify src/server.ts",
"start": "node dist/server.js",
"test": "jest",
"build": "babel src --extensions \".js,.ts\" --out-dir dist --copy-files --no-copy-ignored"
},
"devDependencies": {
"@babel/cli": "^7.10.5",
"@babel/core": "^7.11.0",
"@babel/node": "^7.10.5",
"@babel/preset-env": "^7.11.0",
"@babel/preset-typescript": "^7.10.4",
"@types/express": "^4.17.7",
"@types/jest": "^26.0.8",
"babel-plugin-module-resolver": "^4.0.0",
"eslint": "^7.6.0",
"jest": "^26.2.2",
"ts-jest": "^26.1.4",
"ts-node-dev": "^1.0.0-pre.56",
"tsconfig-paths": "^3.9.0",
"typescript": "^3.9.7"
},
"dependencies": {
"@types/bcrypt": "^3.0.0",
"@types/dotenv": "^8.2.0",
"@types/jwt-simple": "^0.5.33",
"@types/knex": "^0.16.1",
"@types/nodemailer": "^6.4.0",
"@types/passport": "^1.0.4",
"@types/passport-jwt": "^3.0.3",
"@typescript-eslint/eslint-plugin": "^3.8.0",
"@typescript-eslint/parser": "^3.8.0",
"auth": "../modules/auth/dist/auth",
"bcrypt": "^5.0.0",
"eslint-config-standard": "^14.1.1",
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
"express": "^4.17.1",
"jwt-simple": "^0.5.6",
"knex": "^0.21.2",
"nodemailer": "^6.4.11",
"passport": "^0.4.1",
"passport-jwt": "^4.0.0",
"pg": "^8.3.0",
"uuidv4": "^6.2.1"
}
}
package.json
{
"compilerOptions": {
"target": "ES2017",
"module": "commonjs",
"lib": [
"es6"
],
"allowJs": true,
"outDir": "./dist",
"rootDir": "./src",
"removeComments": true,
"strict": false,
"typeRoots": [
"./node_modules/@types",
"./src/@types"
],
"esModuleInterop": true,
"resolveJsonModule": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"baseUrl": ".",
"paths": {
"@controllers/*": [
"./src/controllers/*"
],
"@entities/*": [
"src/entities/*"
],
"@config/*": ["src/config/*"],
"@repositories/*": ["src/repositories/*"],
"@useCases/*": ["src/useCases/*"],
"@utils/*": ["src/utils/*"]
}
},
"include": [
"./src/**/*"
]
}
{
"name": "area-do-cliente",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"scripts": {
"dev": "ts-node-dev -r tsconfig-paths/register --respawn --transpile-only --ignore-watch node_modules --no-notify src/server.ts",
"start": "node dist/server.js",
"test": "jest",
"build": "babel src --extensions \".js,.ts\" --out-dir dist --copy-files --no-copy-ignored"
},
"devDependencies": {
"@babel/cli": "^7.10.5",
"@babel/core": "^7.11.0",
"@babel/node": "^7.10.5",
"@babel/preset-env": "^7.11.0",
"@babel/preset-typescript": "^7.10.4",
"@types/express": "^4.17.7",
"@types/jest": "^26.0.8",
"babel-plugin-module-resolver": "^4.0.0",
"eslint": "^7.6.0",
"jest": "^26.2.2",
"ts-jest": "^26.1.4",
"ts-node-dev": "^1.0.0-pre.56",
"tsconfig-paths": "^3.9.0",
"typescript": "^3.9.7"
},
"dependencies": {
"@types/bcrypt": "^3.0.0",
"@types/dotenv": "^8.2.0",
"@types/jwt-simple": "^0.5.33",
"@types/knex": "^0.16.1",
"@types/nodemailer": "^6.4.0",
"@types/passport": "^1.0.4",
"@types/passport-jwt": "^3.0.3",
"@typescript-eslint/eslint-plugin": "^3.8.0",
"@typescript-eslint/parser": "^3.8.0",
"auth": "../modules/auth/dist/auth",
"bcrypt": "^5.0.0",
"eslint-config-standard": "^14.1.1",
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
"express": "^4.17.1",
"jwt-simple": "^0.5.6",
"knex": "^0.21.2",
"nodemailer": "^6.4.11",
"passport": "^0.4.1",
"passport-jwt": "^4.0.0",
"pg": "^8.3.0",
"uuidv4": "^6.2.1"
}
}
我没有更多的想法去做。有什么帮助吗?很难说,但这是一个非常复杂的工具链。如果您正在使用Babel构建发行版,那么应该使用
Babel节点
,而不是ts节点
。如果还没有的话,这种不一致性会对你造成伤害。babel
是用于生产构建的