Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a module named 'myLib'.
Typescript
declare module [1] {
export function greet(name: string): string;
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to put the module name in quotes.
Using a different module name than 'myLib'.
✗ Incorrect
The module name must be exactly 'myLib' as specified.
2fill in blank
mediumComplete the code to declare a variable 'version' of type string inside the module.
Typescript
declare module 'myLib' { export const [1]: string; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different variable name than 'version'.
Putting the variable name in quotes.
✗ Incorrect
The variable name must be 'version' as specified.
3fill in blank
hardFix the error in the declaration of a function 'add' that takes two numbers and returns a number.
Typescript
declare module 'myLib' { export function add(a: number, b: number)[1] number; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=>' instead of ':'.
Using '=' or '->' which are invalid here.
✗ Incorrect
In TypeScript declaration files, the return type is specified with a colon ':'.
4fill in blank
hardFill both blanks to declare an interface 'User' with a string property 'name' and a number property 'age'.
Typescript
declare module 'myLib' { export interface [1] { name: string; [2]: number; } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong interface or property names.
Confusing property names with variable names.
✗ Incorrect
The interface name is 'User' and the number property is 'age'.
5fill in blank
hardFill both blanks to declare a namespace 'Utils' with a function 'log' that takes a string and returns void.
Typescript
declare namespace [1] { export function [2](message: string): void; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong namespace or function names.
Using '=>' instead of ':' for return type.
✗ Incorrect
The namespace is 'Utils', function name is 'log', and return type uses ':'.