Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include definitely typed files in an Angular2 angular-cli based project

What is the best practice for this scenario:

I have created an Angular2 project using angular-cli (i.e. using ng new)

I want to include TypeScript types from definitely typed

For example, should I use typings to install the types? How do I make sure the types are included in the ng build?

If you answer is that I should hack the webpack settings somehow, please include how I would do that, since I only have the angular-cli.json file

like image 795
Klas Mellbourn Avatar asked Oct 27 '16 09:10

Klas Mellbourn


People also ask

Why we use ts file in Angular?

TypeScript is a primary language for Angular application development. It is a superset of JavaScript with design-time support for type safety and tooling.

What is Typings in angular?

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.

Do I need to install TypeScript for angular?

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.

Does Angular use TypeScript or JavaScript?

Angular is a modern framework built entirely in TypeScript, and as a result, using TypeScript with Angular provides a seamless experience. The Angular documentation not only supports TypeScript as a first-class citizen, but uses it as its primary language.


1 Answers

Angular-cli uses typescript 2.0, you just need to search for the typings on npm, say you want jquery types, just install them:

npm install --save @types/jquery

And that's it. More info here

like image 53
Fabio Antunes Avatar answered Sep 19 '22 12:09

Fabio Antunes