Triple-Slash Directives Flashcards

1
Q

What are triple-slash directives in TypeScript?

A

Triple-slash directives in TypeScript are single-line comments containing a single XML tag. The contents of the comment are used as compiler directives. They are only valid at the top of their containing file and can only be preceded by single or multi-line comments, including other triple-slash directives.

Example:

/// <reference path="..." />
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the syntax of a triple-slash directive in TypeScript?

A

The syntax of a triple-slash directive is as follows:

/// <directive-name path="..." />

For instance, the most common triple-slash directive is:

/// <reference path="..." />
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the purpose of the triple-slash reference directive in TypeScript?

A

The /// <reference path="..." /> directive is a declaration of dependency between files. It instructs the compiler to include additional files in the compilation process and serves as a method to order the output when using out or outFile.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Where can triple-slash directives be placed in a TypeScript file?

A

Triple-slash directives can only be placed at the top of a TypeScript file. They can only be preceded by single or multi-line comments, including other triple-slash directives. If they are encountered following a statement or a declaration, they are treated as regular single-line comments and hold no special meaning.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How does the TypeScript compiler process triple-slash directives?

A

The TypeScript compiler performs a preprocessing pass on input files to resolve all triple-slash reference directives. It starts with a set of root files (specified on the command-line or in the tsconfig.json file) and preprocesses them in the order they are specified. Before a file is added to the list, all its triple-slash references are processed and their targets included. These references are resolved in a depth-first manner, in the order they appear in the file.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How is a triple-slash reference path resolved in TypeScript?

A

A triple-slash reference path in TypeScript is resolved relative to the containing file if a relative path is used. This resolution happens during the preprocessing pass performed by the TypeScript compiler.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How does /// <reference path="..." /> directive work in TypeScript?

A

The /// <reference path="..." /> directive in TypeScript serves as a declaration of dependency between files. It instructs the compiler to include additional files in the compilation process and also serves as a method to order the output when using out or outFile.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does the --noResolve compiler flag do in TypeScript?

A

If the --noResolve compiler flag is specified in TypeScript, triple-slash references are ignored. They neither result in adding new files, nor change the order of the files provided.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the purpose of /// <reference types="..." /> directive in TypeScript?

A

Similar to a /// <reference path="..." /> directive, a /// <reference types="..." /> directive in TypeScript declares a dependency on a package. These are typically used when authoring a d.ts file by hand.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How does /// <reference lib="..." /> directive work in TypeScript?

A

This directive allows a file in TypeScript to explicitly include an existing built-in lib file. This is useful for declaration file authors who rely on built-in types, e.g., DOM APIs or built-in JS run-time constructors like Symbol or Iterable.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What does /// <reference no-default-lib="true"/> directive do in TypeScript?

A

This directive in TypeScript marks a file as a default library and instructs the compiler to not include the default library (i.e., lib.d.ts) in the compilation. The impact here is similar to passing noLib on the command line.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly