Challenge - 5 Problems
Module Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of a simple declared module
What is the output when running this TypeScript code that uses a declared module?
Typescript
declare module 'mathUtils' { export function square(x: number): number; } import { square } from 'mathUtils'; console.log(square(4));
Attempts:
2 left
💡 Hint
Declared modules only provide type information and do not include implementation.
✗ Incorrect
Declared modules in TypeScript only describe types and signatures. Without an actual implementation, importing from 'mathUtils' causes a runtime error.
🧠 Conceptual
intermediate1:30remaining
Purpose of 'declare module' in TypeScript
What is the main purpose of using
declare module in TypeScript?Attempts:
2 left
💡 Hint
Think about how TypeScript handles external JavaScript libraries without type definitions.
✗ Incorrect
declare module is used to tell TypeScript about the shape of modules that exist elsewhere, often JavaScript libraries, so the compiler can check types without needing the actual code.🔧 Debug
advanced2:00remaining
Why does this declared module cause a type error?
Given this declared module and usage, why does TypeScript report an error?
Typescript
declare module 'config' { export const port: string; } import { port } from 'config'; const serverPort: number = port;
Attempts:
2 left
💡 Hint
Check the declared type of
port and the variable it is assigned to.✗ Incorrect
The declared module says
port is a string, but the code tries to assign it to a number variable, causing a type mismatch error.📝 Syntax
advanced2:00remaining
Correct syntax for declaring a module with a default export
Which option correctly declares a module with a default export of a function named
greet?Attempts:
2 left
💡 Hint
Remember the order of keywords for default exports in declarations.
✗ Incorrect
The correct syntax uses
export default function. Other options misuse the order or keywords, causing syntax errors.🚀 Application
expert1:30remaining
Number of properties in a declared module's interface
Given this declared module, how many properties does the interface
Settings have?Typescript
declare module 'appSettings' { interface Settings { theme: string; version: number; debug: boolean; } export const config: Settings; }
Attempts:
2 left
💡 Hint
Count all properties listed inside the interface.
✗ Incorrect
The interface
Settings declares three properties: theme, version, and debug.