无法在Angular 2 Typescript应用程序中找到types.d.ts并声明模块 [英] Unable to find typings.d.ts and declare modules in angular 2 typescript app
问题描述
我是Typescript和Angular 2的新手.我需要安装一个npm依赖项,并在我的angular 2应用程序中使用它.
I am new to Typescript and Angular 2. I need to install an npm dependency and use it in my angular 2 app.
相关性为 https://www.npmjs.com/package/ng2-stomp服务
我已经安装了必要的软件包,但是我需要将以下内容添加到我的typings.d.ts
文件中
I have installed the necessary packages, but I need to add the following to my typings.d.ts
file
declare module 'stompjs';
declare module 'sockjs-client';
我在项目中找不到typings.d.ts
文件.
I am unable to find the typings.d.ts
file in my project.
到目前为止,我已经尝试了以下方法,
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
我有包含内容的typings.json
文件,
{
"dependencies": {
"sockjs-client": "registry:dt/sockjs-client#1.0.3+20160727010356",
"stompjs": "registry:dt/stompjs#2.3.0+20161111105645"
}
}
当我使用npm start
运行我的angular 2应用程序时,会引发如下错误
When I run my angular 2 app with npm start
it throws error as follows
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.
我不确定是什么原因引起的,我猜这是因为我没有在typings.d.ts
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
请告知.谢谢.
推荐答案
我对这次对话的两分钱:
My two cents to this conversation:
在tsconfig.json文件中,确保您具有正确的打字类型d.ts文件路径
In your tsconfig.json file make sure that you have the right path for your typings.d.ts file
"typeRoots":[ "node_modules/@ types", "../src/typings.d.ts" ]
"typeRoots": [ "node_modules/@types", "../src/typings.d.ts" ],
这篇关于无法在Angular 2 Typescript应用程序中找到types.d.ts并声明模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!