Challenge - 5 Problems
Triple-Slash Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of triple-slash directive reference
What will be the output of the following TypeScript code when compiled and run in Node.js?
Assume
/// <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());
Attempts:
2 left
💡 Hint
Triple-slash directives only provide compile-time information, not runtime imports.
✗ Incorrect
Triple-slash directives like
/// <reference path=... /> tell the TypeScript compiler about dependencies but do not import code at runtime. Without an actual import statement, helperFunction is undefined at runtime, causing a ReferenceError.🧠 Conceptual
intermediate1:30remaining
Purpose of triple-slash directives
What is the primary purpose of triple-slash directives in TypeScript?
Attempts:
2 left
💡 Hint
Think about what happens during compilation, not runtime.
✗ Incorrect
Triple-slash directives are comments that instruct the TypeScript compiler about dependencies or types. They do not affect runtime behavior or include code.
🔧 Debug
advanced2:00remaining
Why does this triple-slash directive cause an error?
Consider this triple-slash directive:
What error will the TypeScript compiler produce?
/// <reference types="nonexistent-package" />
console.log('Test');What error will the TypeScript compiler produce?
Attempts:
2 left
💡 Hint
The directive references a type package that does not exist.
✗ Incorrect
The
types attribute in triple-slash directives tells the compiler to include type definitions from a package. If the package is missing, the compiler reports it cannot find the type definition file.📝 Syntax
advanced1: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?
Attempts:
2 left
💡 Hint
Triple-slash directives start with exactly three slashes and use XML-like syntax.
✗ Incorrect
The correct syntax uses three slashes, the
reference tag with the types attribute, and is self-closing with />.🚀 Application
expert2:30remaining
Effect of triple-slash directive on compilation
Given these two files:
What will happen when compiling and running
// 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?Attempts:
2 left
💡 Hint
Triple-slash directives provide type info but do not import implementations.
✗ Incorrect
The triple-slash directive references a declaration file for type checking only. The actual function implementation is missing at runtime, causing a ReferenceError.