Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

TypeScript declares the use of files


May 07, 2021 TypeScript



TypeScript declares the use of files

At TypeScript 2.0, it's easy to get, use, and find claims files. This article will detail how to do these three things.

Download

In versions above TypeScript 2.0, only npm is required to obtain a type declaration file.

For example, to get the claims file for the lodash library, simply use the following command:

npm install --save @types/lodash

Use

Once you're done downloading, you're ready to use lodash directly in TypeScript. Used in both modules and global code.

For example, npm install and you can use import:

import * as _ from "lodash";
_.padStart("Hello TypeScript!", 20, " ");

Or if you're not using a module, you just need to use the _ .

_.padStart("Hello TypeScript!", 20, " ");

Find

In most cases, the name of the type declaration package is always the same as the name of the package on npm but @types/ but you can find your favorite library here in https://aka.ms/types if you need it.

Note: If the claim file you're looking for doesn't exist, you can contribute one, which makes it easier for the next person to use it. Check out the DefinitelyTyped Contribution Guide page to learn more.