[英]Typings isn't working (TypeScript)
I have using this lib in my code 我在代码中使用了这个库
I added typings for it in project like this 我在这样的项目中为其添加了类型
https://www.npmjs.com/package/@types/accounting
https://www.npmjs.com/package/@types/accounting
And include it in .ts file like this 并像这样将其包含在.ts文件中
import accounting from "accounting";
I see typings under /node_modules/@types/accounting
我在
/node_modules/@types/accounting
下看到/node_modules/@types/accounting
But when I try to run project. 但是当我尝试运行项目时。 My webpack showing this
我的webpack显示了这个
./app/javascript/components/helpers.ts
Module not found: Error: Can't resolve 'accounting' in '/Users/nemesises/Documents/GitHub/falco-web/app/javascript/components'
@ ./app/javascript/components/helpers.ts 1:0-36
@ ./app/javascript/components/itinerary/scripts/hotel_results.ts
@ ./app/javascript/components/step1/step1.ts
@ ./app/javascript/components/step1/index.js
@ ./app/javascript/packs/step1.js
@ multi (webpack)-dev-server/client?http://localhost:3035 ./app/javascript/packs/step1.js
tsconfig.json file tsconfig.json文件
{
"compilerOptions": {
"declaration": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"typeRoots": [
"./node_modules/@types"
],
"types": [ "jquery", "accounting" ],
"lib": ["es6", "dom"],
"allowSyntheticDefaultImports": true,
"module": "es6",
"moduleResolution": "node",
"sourceMap": true,
"target": "es5"
},
"exclude": [
"**/*.spec.ts",
"node_modules",
"vendor",
"public"
],
"compileOnSave": false
}
How I can fix it? 我该如何解决?
When using TypeScript, you have to install the types for the module, and the module itself. 使用TypeScript时,必须安装模块的类型以及模块本身。 Preferably like this, so that the types will be added under
devDependencies
, since they're not used at runtime. 最好像这样,以便在
devDependencies
下添加类型,因为在运行时不使用它们。 Add the actual module to use it at runtime, add the types so that TypeScript can check it properly. 添加实际的模块以在运行时使用它,添加类型,以便TypeScript可以正确检查它。
npm install accounting
npm install --save-dev @types/accounting
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.