0
0
Typescriptprogramming~10 mins

Declaration file syntax (.d.ts) 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 variable of type string in a declaration file.

Typescript
declare let message: [1];
Drag options to blanks, or click blank then click option'
Astring
Bnumber
Cboolean
Dany
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'number' or 'boolean' instead of 'string' for text variables.
2fill in blank
medium

Complete the code to declare a function that takes a number and returns a string.

Typescript
declare function formatNumber(value: [1]): string;
Drag options to blanks, or click blank then click option'
Astring
Bboolean
Cnumber
Dany
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'string' as the parameter type instead of 'number'.
3fill in blank
hard

Fix the error in the interface declaration by completing the property type.

Typescript
interface User {
  id: [1];
  name: string;
}
Drag options to blanks, or click blank then click option'
Aboolean
Bnumber
Cany
Dstring
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'string' or 'boolean' for the id property.
4fill in blank
hard

Fill both blanks to declare a module and export a constant string.

Typescript
declare module "myModule" {
  export const version: [1];
  export function getName(): [2];
}
Drag options to blanks, or click blank then click option'
Astring
Bnumber
Cboolean
Dany
Attempts:
3 left
💡 Hint
Common Mistakes
Using different types for version and getName return type.
5fill in blank
hard

Fill all three blanks to declare a namespace with an interface and a function.

Typescript
declare namespace Utils {
  interface Logger {
    log(message: [1]): void;
  }
  function createLogger(level: [2]): Logger;
  const defaultLevel: [3];
}
Drag options to blanks, or click blank then click option'
Astring
Bnumber
Cboolean
Dany
Attempts:
3 left
💡 Hint
Common Mistakes
Using number for log message or logging level.