Reputation: 1492
I am currently attempting to use Scanner-JS in one of my Angular2 projects I have made to try to learn.
I am very new to Angular2, so this question may seem very simple to some of you.
I have installed scanner-js using npm
npm install scanner-js --save
Is there a way I can import this into my typescript?
I have attemped to do the following (please don't laugh)
import { scanner } from 'scanner-js'
But this didn't work I get an error saying
Uncaught ReferenceError: scanner is not defined
Would anybody be able to give me a push in the right direction on how to get this to work?
Thanks in advance.
Upvotes: 2
Views: 2145
Reputation: 41
Replace line:
import { scanner } from 'scanner-js'
with:
declare let scanner;
and make sure you've added scanner.js script to index.html.
Upvotes: 1
Reputation: 5782
in an included .d.ts
file:
declare module 'scanner-js';
And then import your module as you specified. By default when you declare a module like that, it will have the any
type.
Look at working with other js libs and module resolution from the official handbook for more information.
With other popular libraries the .d.ts
types file is already defined by other kind individuals and you can install it like:
npm install --save-dev @types/d3
Upvotes: 1