0
0
Typescriptprogramming~10 mins

Declaring modules 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 a module named "myModule".

Typescript
declare module [1] {
  export const greeting: string;
}
Drag options to blanks, or click blank then click option'
A'myModule'
B"myModule"
CmyModule
D`myModule`
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to use quotes around the module name.
Using backticks or no quotes which causes syntax errors.
2fill in blank
medium

Complete the code to export a function named "sayHello" inside the module.

Typescript
declare module "utils" {
  export function [1](): void;
}
Drag options to blanks, or click blank then click option'
AsayHello
Bhello
Cgreet
DsayHi
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different function name than declared.
Misspelling the function name.
3fill in blank
hard

Fix the error in the module declaration by completing the code correctly.

Typescript
declare module [1] {
  export interface User {
    id: number;
    name: string;
  }
}
Drag options to blanks, or click blank then click option'
A"UserModule"
B'UserModule'
CUserModule
D`UserModule`
Attempts:
3 left
💡 Hint
Common Mistakes
Using single quotes or backticks instead of double quotes.
Not using quotes at all.
4fill in blank
hard

Fill both blanks to declare a module "mathLib" that exports a constant PI with value 3.14.

Typescript
declare module [1] {
  export const PI: [2];
}
Drag options to blanks, or click blank then click option'
A"mathLib"
Bnumber
Cstring
D"PI"
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong type for PI like string.
Not quoting the module name.
5fill in blank
hard

Fill all three blanks to declare a module "shapes" exporting a type Circle and a function area.

Typescript
declare module [1] {
  export type [2] = { radius: number };
  export function [3](c: Circle): number;
}
Drag options to blanks, or click blank then click option'
A"shapes"
BCircle
Carea
DShape
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect module name without quotes.
Mismatching type or function names.