Dan*_*tos 5 node.js typescript
我想在 TypeScript 应用程序中导入url和节点模块。querystring
import url from 'url';
import querystring from 'querystring';
Run Code Online (Sandbox Code Playgroud)
但我收到了以下警告,但我没有从中打字。
[ts] 找不到模块“url”的声明文件。'.../node_modules/url/url.js' 隐式具有“any”类型。尝试它是否存在或添加包含[7016]
npm install @types/url的新声明 (.d.ts) 文件declare module 'url';
我知道url和querystring是节点模块。我已经安装了"@types/node": "^10.12.9",,但它没有解决警告中的输入问题。
我应该怎么做才能从中打字?
信息:我是一个使用 Vue CLI 的前端应用程序
这是我的ts.config
{
"compilerOptions": {
"target": "es5",
"module": "esnext",
"strict": true,
"strictNullChecks": false,
"jsx": "preserve",
"importHelpers": true,
"moduleResolution": "node",
"experimentalDecorators": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"sourceMap": true,
"noImplicitAny": false,
"baseUrl": ".",
"types": ["webpack-env", "mocha", "chai"],
"paths": {
"@/*": ["src/*"]
},
"lib": ["esnext", "dom", "dom.iterable", "scripthost"]
},
"include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.vue", "tests/**/*.ts", "tests/**/*.tsx"],
"exclude": ["node_modules"]
}
Run Code Online (Sandbox Code Playgroud)
和package.json
{
"name": "rating-form",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint",
"test:unit": "vue-cli-service test:unit"
},
"dependencies": {
"axios": "^0.18.0",
"bootstrap": "^4.1.3",
"jquery": "^3.3.1",
"moment": "^2.22.2",
"popper.js": "^1.14.4",
"toastr": "^2.1.4",
"vue": "^2.5.17",
"vue-class-component": "^6.0.0",
"vue-property-decorator": "^7.0.0",
"vue-router": "^3.0.1",
"vue-slider-component": "^2.8.0"
},
"devDependencies": {
"@types/chai": "^4.1.0",
"@types/mocha": "^5.2.4",
"@types/node": "^10.12.9",
"@types/qs": "^6.5.1",
"@types/toastr": "^2.1.35",
"@vue/cli-plugin-typescript": "^3.1.1",
"@vue/cli-plugin-unit-mocha": "^3.1.1",
"@vue/cli-service": "^3.1.1",
"@vue/test-utils": "^1.0.0-beta.20",
"chai": "^4.1.2",
"ts-node": "^7.0.1",
"typescript": "^3.1.6",
"vue-template-compiler": "^2.5.17"
}
}
Run Code Online (Sandbox Code Playgroud)
在 中tsconfig.json,您必须添加"node"到"types"数组:
"baseUrl": ".",\n "types": ["webpack-env", "mocha", "chai", "node"],\n "paths": {\nRun Code Online (Sandbox Code Playgroud)\n\xe2\x80\xa6 或完全删除数组(这就是我要做的):
\n "baseUrl": ".",\n "paths": {\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
7546 次 |
| 最近记录: |