Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a type that is not in the union to exclude.
Confusing Exclude with Extract.
✗ Incorrect
The Exclude type removes the specified type from the union. Here, 'string' is excluded.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Excluding only one of the types instead of both.
Using a single type instead of a union.
✗ Incorrect
Exclude removes all types in the second parameter from the first union type. Here, both 'null' and 'undefined' are excluded.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Excluding a type not present in the union.
Using 'never' which excludes nothing.
✗ Incorrect
To exclude 'number' from the union, you must specify 'number' as the second parameter.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the two blanks.
Excluding types not in the original union.
✗ Incorrect
The first blank is the original union type. The second blank is the union of types to exclude.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Not including all types in the first blank.
Excluding only some of the unwanted types.
✗ Incorrect
The first blank is the full union type. The second and third blanks are types to exclude combined with '|'.