Recall & Review
beginner
What is a custom declaration file in TypeScript?
A custom declaration file (.d.ts) tells TypeScript about the types of code written in JavaScript or external libraries without type definitions. It helps TypeScript understand the shape and types of those modules.
Click to reveal answer
beginner
How do you declare a module in a custom declaration file?
Use the
declare module 'module-name' { ... } syntax to describe the types and exports of that module inside the curly braces.Click to reveal answer
beginner
Why use
declare keyword in declaration files?The
declare keyword tells TypeScript that the code exists elsewhere (like JavaScript code) and only describes its shape or types without generating JavaScript code.Click to reveal answer
intermediate
How to declare a function type in a custom declaration file?
Inside the declaration file, write the function signature like <code>function myFunc(param: string): number;</code> inside a module or global scope to describe its parameters and return type.Click to reveal answer
beginner
What is the purpose of
export in declaration files?Using <code>export</code> inside a declaration file makes the declared types, interfaces, or functions available to other files that import the module.Click to reveal answer
What file extension is used for TypeScript declaration files?
✗ Incorrect
Declaration files always use the .d.ts extension to tell TypeScript about types without generating JavaScript.
Which keyword is used to declare a module in a custom declaration file?
✗ Incorrect
The 'declare' keyword is used to declare modules and other types in declaration files.
What does the 'declare' keyword do in a declaration file?
✗ Incorrect
'declare' tells TypeScript about existing code's types without creating JavaScript output.
How do you specify a function's return type in a declaration file?
✗ Incorrect
In declaration files, function signatures end with a semicolon and specify return type after colon.
Why add 'export' inside a declaration file?
✗ Incorrect
'export' makes declared types or functions accessible to other files importing the module.
Explain how to write a custom declaration file for a JavaScript module without types.
Think about how to tell TypeScript about a JS module's shape.
You got /5 concepts.
Describe the role of the 'declare' keyword in TypeScript declaration files.
It tells TypeScript about something without creating code.
You got /4 concepts.