typescript 如何使用NPM @types/ package中的TS类型< package-name>?

dwbf0jvd  于 2023-02-20  发布在  TypeScript
关注(0)|答案(1)|浏览(155)

我使用的是ssh2-sftp-client NPM包,它的类型是由@types/ssh2-sftp-client提供的。我安装了这两个包,但没有选择任何类型。这是我的package.json的外观:

{
  "name": "name",
  "version": "0.1.0",
  "description": "description",
  "devDependencies": {
    "@types/ssh2": "^1.11.7",
    "@types/ssh2-sftp-client": "^9.0.0"
  },
  "dependencies": {
    "ssh2-sftp-client": "^9.0.4"
  }
}

有一个related answer,但是它似乎处理了你自己声明的类型。在安装了任何@typings包之后,我需要做进一步的设置吗?
编辑...我忘了添加tsconfig.json文件:

"compilerOptions": {
    "lib": ["ES2022"],
    "module": "commonjs",
    "target": "ES2022",
    "declaration": true,
    "strict": true,
    "noImplicitAny": true,
    "strictNullChecks": true,
    "noImplicitThis": true,
    "alwaysStrict": true,
    "noUnusedLocals": false,
    "noUnusedParameters": false,
    "noImplicitReturns": true,
    "noFallthroughCasesInSwitch": false,
    "inlineSourceMap": true,
    "inlineSources": true,
    "experimentalDecorators": true,
    "skipLibCheck": true,
    "strictPropertyInitialization": false,
    "typeRoots": [
      "./node_modules/@types"
    ]
  },
  "exclude": [
    "node_modules/**/*",
    "cdk.out"
  ]
}
1tuwyuhd

1tuwyuhd1#

正如@Yury Tarabanko所建议的那样,我重新启动了语言服务器,这就成功了。在VSCode上,按Cmd/Ctrl + Shift + P调出命令面板,然后搜索/运行Developer: Reload Window

相关问题