TypeScript language compilation command

 

1. Installation

npm install -g typescript

2. Compile

The tsc tool is the console interface of the TypeScript compiler, which can compile TypeScript files into JavaScript files;

  1. Compile the file:
    tsc [options] [file ...]
    
  2. View the help information of the compilation command:
    tsc --help
    
    or
    tsc -h
    
    or
    tsc --all
    

3. Type description file

Using type description files in TypeScript 2.0 and later

Since TypeScript 2.0 and later use the npm tool to manage TypeScript type description files, the download and search of TypeScript type description files are based on npm, as follows:

  1. Download:
    In versions above TypeScript 2.0, you only need to use npm to get the type declaration file.
    For example, to get the declaration file of the lodash library, just use the following command:

    npm install --save @types/lodash
    
  2. Use:
    After downloading, you can use lodash directly in TypeScript. Whether used in modules or global code;

  3. Find:

    npm search @types/[类型描述文件的名字]
    

For the most part, type declaration packages are always named the same as their packages on npm, but prefixed with @types/, but if you need it, you can look up your favorite library here ;

How to use before TypeScript 2.0

tsd is a tool for managing TypeScript type description files; like npm and bower, it also has its own configuration file, named tsd.json, and will save all downloaded description files in the typings directory;

  1. Install the tsd tool:
    npm install tsd 0-g
    
  2. View help information:
    tsd --help
    
  3. Create and initialize the tsd.json configuration file and typings directory:
    tsd init
    
  4. Installation description file:
    tsd install [名字]
    
  5. Search type description files:
    tsd query <...pattern>

Guess you like

Origin blog.csdn.net/s178435865/article/details/130643239