Recall & Review
beginner
What is an ambient declaration in TypeScript?
An ambient declaration tells TypeScript about variables, functions, or types that exist elsewhere (like in JavaScript files or external libraries) without defining them in the current file.
Click to reveal answer
beginner
How do you declare an ambient variable in TypeScript?
Use the <code>declare</code> keyword before the variable name, for example: <pre>declare const myVar: string;</pre> This means <code>myVar</code> exists somewhere else.Click to reveal answer
intermediate
Why use ambient declarations instead of normal declarations?
Ambient declarations avoid redefining or implementing code that already exists, helping TypeScript understand external code without duplication or errors.
Click to reveal answer
intermediate
What is the difference between
declare var and declare module?declare var tells TypeScript about a global variable, while declare module describes an external module or library's shape.Click to reveal answer
beginner
Can ambient declarations include function signatures?
Yes! You can declare functions with
declare function to tell TypeScript about functions defined elsewhere, including their parameters and return types.Click to reveal answer
What keyword is used to create an ambient declaration in TypeScript?
✗ Incorrect
The
declare keyword is used to tell TypeScript about variables or functions that exist elsewhere.Which of the following is a correct ambient declaration for a global variable named
apiKey of type string?✗ Incorrect
Ambient declarations use
declare without assigning a value.What does an ambient module declaration describe?
✗ Incorrect
Ambient module declarations describe external modules or libraries.
Can ambient declarations include implementations (code bodies)?
✗ Incorrect
Ambient declarations only describe the shape, not the implementation.
Where are ambient declarations commonly used?
✗ Incorrect
They help TypeScript understand external JavaScript code.
Explain what ambient declarations are and why they are useful in TypeScript.
Think about how TypeScript knows about code written outside your files.
You got /4 concepts.
Write an example of an ambient declaration for a function named
fetchData that takes a string and returns a Promise of any.Use the declare keyword and only write the function signature.
You got /4 concepts.