0
0
Typescriptprogramming~10 mins

Ambient declarations in Typescript - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare an ambient variable named myVar of type string.

Typescript
declare var [1]: string;
Drag options to blanks, or click blank then click option'
AvarName
BmyVariable
CmyVar
Dvariable
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different variable name than myVar.
Trying to assign a value instead of declaring.
2fill in blank
medium

Complete the code to declare an ambient function named greet that takes a name parameter of type string and returns void.

Typescript
declare function [1](name: string): void;
Drag options to blanks, or click blank then click option'
Agreet
BsayHello
Chello
Dwelcome
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different function name.
Adding a function body instead of just declaring.
3fill in blank
hard

Fix the error in the ambient declaration by completing the code to declare a constant named PI of type number.

Typescript
declare const [1]: number;
Drag options to blanks, or click blank then click option'
ApiValue
BPI
Cpi
DPi
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase or mixed case names.
Trying to assign a value in ambient declarations.
4fill in blank
hard

Fill both blanks to declare an ambient namespace named Utils with a function log that takes a message string and returns void.

Typescript
declare namespace [1] {
  function [2](message: string): void;
}
Drag options to blanks, or click blank then click option'
AUtils
BLogger
Clog
Dprint
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong namespace or function names.
Trying to add function bodies inside ambient declarations.
5fill in blank
hard

Fill all three blanks to declare an ambient interface named Person with a name property of type string and an optional age property of type number.

Typescript
declare interface [1] {
  [2]: string;
  [3]?: number;
}
Drag options to blanks, or click blank then click option'
APerson
Bname
Cage
DUser
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong interface or property names.
Missing the optional property marker ?.