0
0
Typescriptprogramming~5 mins

Triple-slash directives in Typescript - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a triple-slash directive in TypeScript?
A triple-slash directive is a single-line comment starting with /// that provides compiler instructions, like referencing other files or types.
Click to reveal answer
beginner
How do you reference another file using a triple-slash directive?
You use /// <reference path="filename.ts" /> at the top of your TypeScript file to tell the compiler to include that file.
Click to reveal answer
intermediate
What is the purpose of /// <reference types="..." /> directive?
It tells the compiler to include type declarations from a package, usually from node_modules/@types, so you get type info for libraries.
Click to reveal answer
beginner
Where should triple-slash directives be placed in a TypeScript file?
They must be placed at the very top of the file, before any other code or import statements.
Click to reveal answer
intermediate
Can triple-slash directives affect module resolution in TypeScript?
Yes, they can guide the compiler to find files or types that are not automatically discovered, helping with module resolution.
Click to reveal answer
What does the triple-slash directive /// <reference path="utils.ts" /> do?
AComments out the utils.ts file
BImports a module named utils
CDeclares a variable named utils
DIncludes the file utils.ts for compilation
Where must triple-slash directives appear in a TypeScript file?
AAt the very top before any code
BAt the bottom of the file
CAnywhere in the file
DInside functions only
Which triple-slash directive is used to include type declarations from a package?
A/// <reference path="..." />
B/// <include types="..." />
C/// <reference types="..." />
D/// <import types="..." />
What symbol starts a triple-slash directive in TypeScript?
A//
B///
C/*
D<!--
Can triple-slash directives be used to affect module resolution?
AYes, they help the compiler find files or types
BNo, they only add comments
CYes, but only for JavaScript files
DNo, they are deprecated
Explain what triple-slash directives are and how they are used in TypeScript.
Think about how TypeScript knows about other files or type info.
You got /4 concepts.
    Describe the difference between /// <reference path="..." /> and /// <reference types="..." /> directives.
    One is for files, the other is for type packages.
    You got /4 concepts.