无法在 angular 2 typescript 应用程序中找到typings.d.ts 和声明模块
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/44377617/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Unable to find typings.d.ts and declare modules in angular 2 typescript app
提问by LINGS
I am new to Typescript and Angular 2. I need to install an npm dependency and use it in my angular 2 app.
我是 Typescript 和 Angular 2 的新手。我需要安装一个 npm 依赖项并在我的 angular 2 应用程序中使用它。
The dependency is https://www.npmjs.com/package/ng2-stomp-service
依赖项是https://www.npmjs.com/package/ng2-stomp-service
I have installed the necessary packages, but I need to add the following to my typings.d.ts
file
我已经安装了必要的软件包,但我需要将以下内容添加到我的typings.d.ts
文件中
declare module 'stompjs';
declare module 'sockjs-client';
I am unable to find the typings.d.ts
file in my project.
我无法typings.d.ts
在我的项目中找到该文件。
I have tried the following so far,
到目前为止,我已经尝试了以下方法,
npm install typings --global
npm install @types/stompjs
npm isntall @types/sockjs-client
typings install dt~stompjs --save
typings install dt~sockjs-client --save
I have typings.json
file with contents,
我有typings.json
包含内容的文件,
{
"dependencies": {
"sockjs-client": "registry:dt/sockjs-client#1.0.3+20160727010356",
"stompjs": "registry:dt/stompjs#2.3.0+20161111105645"
}
}
When I run my angular 2 app with npm start
it throws error as follows
当我运行我的 angular 2 应用程序时,npm start
它会引发如下错误
ERROR in D:/Userfiles/subramanians/projects/hand-cricket/node_modules/ng2-stomp-service/dist/stomp.service.ts (27,2): Member 'config' implicitly has an 'any' type.
ERROR in D:/Userfiles/subramanians/projects/hand-cricket/node_modules/ng2-stomp-service/dist/stomp.service.ts (36,2): Member 'queuePromises' implicitly has an 'any[]' type.
ERROR in D:/Userfiles/subramanians/projects/hand-cricket/node_modules/ng2-stomp-service/dist/stomp.service.ts (83,32): Parameter 'str' implicitly has an 'any' type.
ERROR in D:/Userfiles/subramanians/projects/hand-cricket/node_modules/ng2-stomp-service/dist/stomp.service.ts (132,53): Parameter 'response' implicitly has an 'any' type.
ERROR in D:/Userfiles/subramanians/projects/hand-cricket/node_modules/ng2-stomp-service/dist/stomp.service.ts (27,2): Member 'config' implicitly has an 'any' type.
ERROR in D:/Userfiles/subramanians/projects/hand-cricket/node_modules/ng2-stomp-service/dist/stomp.service.ts (36,2): Member 'queuePromises' implicitly has an 'any[]' type.
ERROR in D:/Userfiles/subramanians/projects/hand-cricket/node_modules/ng2-stomp-service/dist/stomp.service.ts (83,32): Parameter 'str' implicitly has an 'any' type.
ERROR in D:/Userfiles/subramanians/projects/hand-cricket/node_modules/ng2-stomp-service/dist/stomp.service.ts (132,53): Parameter 'response' implicitly has an 'any' type.
I am not sure what is causing the issue, I am guessing it is because I have not declared the modules in typings.d.ts
我不确定是什么导致了这个问题,我猜是因为我没有在 typings.d.ts
Please advise. Thank you.
请指教。谢谢你。
回答by Amadeus Sánchez
My two cents to this conversation:
我对这次谈话的两分钱:
In your tsconfig.json file make sure that you have the right path for your typings.d.ts file
在您的 tsconfig.json 文件中,确保您的 Typings.d.ts 文件的路径正确
"typeRoots": [ "node_modules/@types", "../src/typings.d.ts" ],
"typeRoots": [ "node_modules/@types", "../src/typings.d.ts"],
回答by Daniel Kucal
It seems like your Typescript compiler tries to compile files from node_modules
directory.
您的 Typescript 编译器似乎试图从node_modules
目录编译文件。
Please make sure you have this excluding rule in your tsconfig.json
file:
请确保您的tsconfig.json
文件中有此排除规则:
{
"compilerOptions": {},
"exclude": [
"node_modules"
]
}
Btw. you need just one of @types
and typings
. The second one is deprecated, all you need is proper @types
packages included in your dev dependencies. Hope it helps!
顺便提一句。您只需要@types
和 之一typings
。第二个已弃用,您只需要@types
在开发依赖项中包含适当的包即可。希望能帮助到你!
EDIT: I think there shouldn't be any Typescript files in npm package, so I've created a topic with fix on this repository's github: https://github.com/devsullo/ng2-STOMP-Over-WebSocket/issues/5
编辑:我认为 npm 包中不应该有任何 Typescript 文件,所以我在这个存储库的 github 上创建了一个修复主题:https: //github.com/devsullo/ng2-STOMP-Over-WebSocket/issues/ 5
回答by Devsullo
If you are not using new version of angular you can't find typings.d.ts
file in your project. My suggestion is to update your project using angular CLI https://cli.angular.io/
如果您没有使用新版本的 angular,则typings.d.ts
在您的项目中找不到文件。我的建议是使用 angular CLI https://cli.angular.io/更新您的项目