0
0
Typescriptprogramming~20 mins

Triple-slash directives in Typescript - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Triple-Slash Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of triple-slash directive reference
What will be the output of the following TypeScript code when compiled and run in Node.js?

/// <reference path="./helper.ts" />

console.log(helperFunction());

Assume helper.ts contains export function helperFunction() { return 'Hello from helper'; } and is correctly referenced.
Typescript
/// <reference path="./helper.ts" />

console.log(helperFunction());
AReferenceError: helperFunction is not defined
BHello from helper
CSyntaxError: Unexpected token <
DTypeError: helperFunction is not a function
Attempts:
2 left
💡 Hint
Triple-slash directives only provide compile-time information, not runtime imports.
🧠 Conceptual
intermediate
1:30remaining
Purpose of triple-slash directives
What is the primary purpose of triple-slash directives in TypeScript?
ATo execute code before the main program runs
BTo include external JavaScript files at runtime
CTo provide compiler with additional type information or dependencies
DTo define global variables accessible everywhere
Attempts:
2 left
💡 Hint
Think about what happens during compilation, not runtime.
🔧 Debug
advanced
2:00remaining
Why does this triple-slash directive cause an error?
Consider this triple-slash directive:

/// <reference types="nonexistent-package" />

console.log('Test');

What error will the TypeScript compiler produce?
ARuntime error: module not found.
BSyntaxError: Invalid triple-slash directive syntax.
CNo error, code compiles and runs fine.
DCannot find type definition file for 'nonexistent-package'.
Attempts:
2 left
💡 Hint
The directive references a type package that does not exist.
📝 Syntax
advanced
1:30remaining
Identify the correct triple-slash directive syntax
Which of the following is the correct syntax for a triple-slash directive referencing a type definition package?
A/// <reference types="express" />
B// <reference types="express" />
C/// reference types="express" /
D/// <reference path="express" />
Attempts:
2 left
💡 Hint
Triple-slash directives start with exactly three slashes and use XML-like syntax.
🚀 Application
expert
2:30remaining
Effect of triple-slash directive on compilation
Given these two files:

// math.d.ts
export function add(a: number, b: number): number;

// main.ts
/// 

console.log(add(2, 3));

What will happen when compiling and running main.ts with tsc and Node.js?
ACompilation fails with error: Cannot find name 'add'.
BCompilation succeeds, runtime throws ReferenceError: add is not defined
CCompilation and runtime succeed, output: 5
DCompilation succeeds, runtime throws TypeError: add is not a function
Attempts:
2 left
💡 Hint
Triple-slash directives provide type info but do not import implementations.