0
0
Typescriptprogramming~5 mins

Declaration file syntax (.d.ts) in Typescript - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AImports external libraries
BImplements functions and variables
CDefines the shape of variables, functions, or modules without implementation
DRuns TypeScript code
Which file extension is used for TypeScript declaration files?
A.d.ts
B.tsx
C.ts
D.js
Can you write executable code inside a .d.ts file?
AYes, it runs like normal TypeScript
BNo, it only contains type declarations
COnly for functions
DOnly for variables
How do you declare a class in a .d.ts file?
AUse <code>function ClassName() { ... }</code>
BUse <code>class ClassName { ... }</code> without declare
CUse <code>interface ClassName { ... }</code>
DUse <code>declare class ClassName { ... }</code>
Which of the following can you NOT declare in a .d.ts file?
AFunction implementations
BFunctions
CModules
DVariables
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.