“This is the 27th day of my participation in the Gwen Challenge in November. See details of the event: The Last Gwen Challenge in 2021”

preface

The content of today’s lecture is TS thing, called the three slash instruction

///


The body of the

What is a triple slash instruction

As in ///

above, the format is three slashes followed by a label

You can think of it as a single-line comment, except that it is special and is parsed as a compiler instruction

You can also think of it as import, which tells the compiler about additional files to import during compilation

A position

The position of the three slash instruction is particular

It must be placed at the very top of the file, except that other comments may appear before a triple-slash directive, including single-line, multi-line, and triple-slash directives

Otherwise, the triple slash command will be treated as a normal one-line comment without any special meaning

Common three slash instruction

  • /// <reference path="..." />

Used to declare dependencies between files

  • /// <reference types="..." />

Used to declare a dependency on a package

  • /// <reference no-default-lib="true"/>

Used to mark a file as the default library

  • /// <amd-module />

Used to pass an optional module name to the compiler

  • /// <amd-dependency path="x"/>

Tells the compiler that a non-TS module dependency needs to be injected; However, this directive has been replaced with the import “x” statement

Pay attention to the point

A few additional points need to be added:

  1. The compiler preprocesses the input file to parse all the tri-slash reference instructions
  2. An error is reported when a file references a nonexistent file with the triple slash command
  3. If you specify--noResolveThe compiler option, triple slash references are ignored, neither introducing new files nor changing the order of a given file

END

That’s all for this article. If you have any questions, please point out