0
0
Typescriptprogramming~5 mins

Exclude type in Typescript - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the Exclude<T, U> type do in TypeScript?
It creates a new type by removing from T all types that are assignable to U. Think of it as filtering out unwanted types from a set.
Click to reveal answer
beginner
Given type A = 'a' | 'b' | 'c' and type B = 'a' | 'c', what is Exclude<A, B>?
The result is 'b' because 'a' and 'c' are removed from A since they are in B.
Click to reveal answer
intermediate
How can Exclude help when working with union types?
It helps you create a new type by excluding certain members from a union, making your types more precise and avoiding unwanted values.
Click to reveal answer
beginner
Is Exclude<string | number, number> equivalent to string?
Yes. It removes number from the union, leaving only string.
Click to reveal answer
intermediate
Can Exclude be used with non-union types?
Yes, but if T is not a union, it either returns T if it is not assignable to U, or never if it is assignable.
Click to reveal answer
What is the result of Exclude<'x' | 'y' | 'z', 'y' | 'a'>?
A'x' | 'z'
B'y' | 'a'
C'x' | 'y' | 'z'
D'a'
Which utility type removes types from a union?
APick
BPartial
CExclude
DRecord
What does Exclude<number | string, string> evaluate to?
Anumber
Bstring
Cnumber | string
Dnever
If T is 'a' and U is 'a', what is Exclude<T, U>?
Aunknown
B'a'
Cstring
Dnever
Can Exclude be used to exclude types other than string literals?
ANo, only string literals
BYes, it works with any types
COnly with numbers
DOnly with boolean
Explain how the Exclude type works in TypeScript and give a simple example.
Think about filtering out unwanted types from a set.
You got /3 concepts.
    Describe a practical scenario where using Exclude would help improve your TypeScript code.
    Consider when you want to remove some options from a list of possible values.
    You got /3 concepts.