I have a SPA with Angular CLI framework and a Javascript library written by a team member. I need to inject this JS file into the app. My thought is
My question is how to add the custom type definition file into my Angular CLI app? (I know the JS file can be added from "scripts": []
in .angular-cli.json file, right?)
I saw some posts for adding external js library to angular-cli, but they all seem on npm which doesn't work for me apparently.
Typings describes contract of libraries you use. This allows the TypeScript compiler that what you use exist (classes, properties, ...). You can install typings from a repository using the typings command or let the compiler find out them leveraging the strategy specified in the tsconfig.
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.
Knowledge of TypeScript is helpful, but not required. Angular requires an active LTS or maintenance LTS version of Node.js. For information about specific version requirements, see the engines key in the package.json file. For more information on installing Node.js, see nodejs.org.
Since Angular utilizes decorators and class properties heavily and Babel doesn't support them in those presets, we need to add them manually. Please note that plugin-proposal-decorators needs to be additionally configured — we need to use legacy decorators mode.
You have a couple of options here:
In the src
dir for newly created applications there is a file typings.d.ts
which you can use reference your team member's .d.ts
file which will expose those types throughout your application.
In the tsconfig.json
file you can add the path to the node_modules
folder where this package lives to the typeRoots
array which will make those typing available too.
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