节点将url和querystring类型导入TypeScript应用程序

时间:2018-11-21 12:54:16

标签: node.js typescript

我想在TypeScript应用程序中导入urlquerystring节点模块。

import url from 'url';
import querystring from 'querystring';

但是我收到了警告,并且没有从中键入内容。

  

[ts]找不到模块'url'的声明文件。 '... / node_modules / url / url.js'隐式具有'any'类型。     如果存在,请尝试npm install @types/url或添加一个包含declare module 'url'; [7016]

的新声明(.d.ts)文件

我知道urlquerystring是节点模块。我已经安装了"@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"]
}

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"
  }
}

0 个答案:

没有答案