0
0
Typescriptprogramming~10 mins

Writing custom declaration files 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 'myLib'.

Typescript
declare module [1] {
  export function greet(name: string): string;
}
Drag options to blanks, or click blank then click option'
A'library'
B'lib'
C'myLib'
D'myLibrary'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to put the module name in quotes.
Using a different module name than 'myLib'.
2fill in blank
medium

Complete 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'
Aversion
Bver
Cv
DverNum
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different variable name than 'version'.
Putting the variable name in quotes.
3fill in blank
hard

Fix 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'
A=>
B=
C->
D:
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=>' instead of ':'.
Using '=' or '->' which are invalid here.
4fill in blank
hard

Fill 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'
AUser
Busername
Cage
Did
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong interface or property names.
Confusing property names with variable names.
5fill in blank
hard

Fill 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'
AUtils
Blog
C:
DLogger
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong namespace or function names.
Using '=>' instead of ':' for return type.