Reputation: 1664
I installed @types/[email protected], then in tsconfig.json I added jquery.cookie in types section. Visual Studio Code shows that $.cookie is available to use, but when I run my code I get error in console that $.cookie() is not a function. Where is the problem? Am I missing something? Should I reference it somewhere else?
Upvotes: 0
Views: 760
Reputation: 17617
Have you included the jquery.cookie
package in your code? Or just the @types/[email protected]
?
@types
are just definition files for TypeScript, not the actual code it self. So we still need to install the code it self:
npm install --save jquery.cookie
Then add it to your packaging, for instance for SystemJS:
SystemJS.config({
'map': {
'jquery.cookie': 'npm:jquery.cookie'
},
'paths': {
'npm:': 'node_modules/'
}
});
To sum up:
@types
are definitions to allow TypeScript understand code/packages written in JavaScript (as most of them are or at least compiled to). @types
shouldn't be imported in the code it self. Only installed, the TypeScript compiler automatically looks for all defintions in node_modules/@types
.npm
(or yarn
). These hold the actual code.Upvotes: 1