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.
The "d. ts" file is used to provide typescript type information about an API that's written in JavaScript. The idea is that you're using something like jQuery or underscore, an existing javascript library. You want to consume those from your typescript code.
The error "Could not find declaration file for module" occurs when TypeScript cannot find the type declaration for a module. To solve the error, install the types for the module by running the command from the error message, e.g. npm install -D @types/module-name .
Typings is an NPM package to handle the type definitions associated with third-party libraries. This way the tooling will be aware of the types used inside the application. After explaining the typings library, Scott summarizes the different coding syntax options with Angular 2.
ts: This file is a unit testing file related to app component. This file is used along with other unit tests. It is run from Angular CLI by the command ng test. app.
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" ],
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
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With