0
0
Typescriptprogramming~10 mins

Exclude type 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 exclude the type 'string' from the union.

Typescript
type Result = Exclude<string | number | boolean, [1]>;
Drag options to blanks, or click blank then click option'
Astring
Bboolean
Cnumber
Dany
Attempts:
3 left
💡 Hint
Common Mistakes
Using a type that is not in the union to exclude.
Confusing Exclude with Extract.
2fill in blank
medium

Complete the code to exclude 'null' and 'undefined' from the type.

Typescript
type NonNullableType = Exclude<string | null | undefined, [1]>;
Drag options to blanks, or click blank then click option'
Anull | undefined
Bstring
Cnull
Dundefined
Attempts:
3 left
💡 Hint
Common Mistakes
Excluding only one of the types instead of both.
Using a single type instead of a union.
3fill in blank
hard

Fix the error in excluding 'number' from the union type.

Typescript
type CleanType = Exclude<string | number | boolean, [1]>;
Drag options to blanks, or click blank then click option'
Aboolean
Bnumber
Cstring
Dnever
Attempts:
3 left
💡 Hint
Common Mistakes
Excluding a type not present in the union.
Using 'never' which excludes nothing.
4fill in blank
hard

Fill both blanks to exclude 'string' and 'boolean' from the union.

Typescript
type Filtered = Exclude<[1], [2]>;
Drag options to blanks, or click blank then click option'
Astring | number | boolean
Bstring | boolean
Cnumber | boolean
Dstring | number
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the two blanks.
Excluding types not in the original union.
5fill in blank
hard

Fill all three blanks to exclude 'null' and 'undefined' from the union.

Typescript
type Cleaned = Exclude<[1], [2] | [3]>;
Drag options to blanks, or click blank then click option'
Astring | number | boolean | null | undefined | false
Bnull
Cundefined
Dfalse
Attempts:
3 left
💡 Hint
Common Mistakes
Not including all types in the first blank.
Excluding only some of the unwanted types.