0
0
Typescriptprogramming~10 mins

Why advanced types are needed in Typescript - Test Your Understanding

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

Complete the code to declare a variable with a string type.

Typescript
let name: [1] = "Alice";
Drag options to blanks, or click blank then click option'
Astring
Bnumber
Cany
Dboolean
Attempts:
3 left
💡 Hint
Common Mistakes
Using number or boolean instead of string.
2fill in blank
medium

Complete the code to define a function that returns a number.

Typescript
function getAge(): [1] {
  return 30;
}
Drag options to blanks, or click blank then click option'
Avoid
Bstring
Cnumber
Dboolean
Attempts:
3 left
💡 Hint
Common Mistakes
Using string or void as return type.
3fill in blank
hard

Fix the error in the code by completing the type for the parameter.

Typescript
function greet(person: [1]) {
  console.log("Hello, " + person);
}
Drag options to blanks, or click blank then click option'
Aany
Bboolean
Cnumber
Dstring
Attempts:
3 left
💡 Hint
Common Mistakes
Using number or boolean causes errors.
4fill in blank
hard

Fill both blanks to create a type that can be either a string or a number.

Typescript
let value: [1] = 42;
value = [2];
Drag options to blanks, or click blank then click option'
Astring | number
B"hello"
Ctrue
Dfalse
Attempts:
3 left
💡 Hint
Common Mistakes
Using only string or number alone.
5fill in blank
hard

Fill all three blanks to create a function type that takes a number and returns a boolean.

Typescript
type Check = ([1]: [2]) => [3];
Drag options to blanks, or click blank then click option'
Anum
Bnumber
Cboolean
Dstring
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong parameter or return types.