Reputation: 3630
I am new to Typescript and Angular 2. I need to install an npm dependency and use it in my angular 2 app.
The dependency is 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
declare module 'stompjs';
declare module 'sockjs-client';
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
I have typings.json
file with contents,
{
"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
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
Please advise. Thank you.
Upvotes: 9
Views: 28788
Reputation: 2565
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
"typeRoots": [ "node_modules/@types", "../src/typings.d.ts" ],
Upvotes: 17
Reputation: 9232
It seems like your Typescript compiler tries to compile files from node_modules
directory.
Please make sure you have this excluding rule in your tsconfig.json
file:
{
"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!
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
Upvotes: 3
Reputation: 914
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/
Upvotes: 2