Recall & Review
beginner
What is the purpose of a
.d.ts file in TypeScript?A
.d.ts file provides type declarations for JavaScript code, allowing TypeScript to understand the types without the actual implementation code.Click to reveal answer
beginner
How do you declare a variable in a
.d.ts file?Use the <code>declare</code> keyword followed by the variable name and its type, for example: <code>declare const myVar: string;</code>Click to reveal answer
beginner
What keyword is used to declare a function signature in a
.d.ts file?The <code>declare</code> keyword is used before the function signature, for example: <code>declare function greet(name: string): void;</code>Click to reveal answer
intermediate
How do you declare a module in a
.d.ts file?Use the
declare module 'module-name' { ... } syntax to describe the module's types and exports.Click to reveal answer
beginner
Can you include implementation code inside a
.d.ts file?No,
.d.ts files only contain type declarations without any actual code implementation.Click to reveal answer
What does the
declare keyword do in a .d.ts file?✗ Incorrect
The
declare keyword tells TypeScript about the existence and type of variables, functions, or modules without providing their implementation.Which file extension is used for TypeScript declaration files?
✗ Incorrect
Declaration files use the
.d.ts extension to provide type information without implementation.Can you write executable code inside a
.d.ts file?✗ Incorrect
.d.ts files only describe types and do not contain executable code.How do you declare a class in a
.d.ts file?✗ Incorrect
Classes in declaration files are declared with the
declare keyword to describe their shape without implementation.Which of the following can you NOT declare in a
.d.ts file?✗ Incorrect
Declaration files only declare types and signatures, not implementations.
Explain the role of the
.d.ts file in a TypeScript project and how it helps with JavaScript libraries.Think about how TypeScript knows types for code it doesn't compile.
You got /4 concepts.
Describe how to declare a module and a function inside a
.d.ts file.Focus on the keywords and structure used for declarations.
You got /4 concepts.