0
0
Typescriptprogramming~5 mins

Omit type in Typescript - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the Omit type do in TypeScript?
The Omit type creates a new type by removing one or more specified keys from an existing type.
Click to reveal answer
beginner
How do you use Omit to remove the property age from a type Person?
You write Omit<Person, 'age'> to create a new type without the age property.
Click to reveal answer
intermediate
Given type Person = { name: string; age: number; city: string; }, what is Omit<Person, 'age' | 'city'>?
It is a type with only the name property, because age and city are removed.
Click to reveal answer
beginner
Can Omit be used to remove multiple properties at once?
Yes, you can remove multiple properties by listing them as a union of keys, like Omit<Type, 'key1' | 'key2'>.
Click to reveal answer
intermediate
What is the difference between Pick and Omit types?
Pick creates a type by selecting specific keys, while Omit creates a type by removing specific keys.
Click to reveal answer
What does Omit<User, 'password'> do?
ACreates a type like User but without the password property
BCreates a type with only the password property
CAdds a password property to User
DRenames the password property
Which syntax correctly removes multiple keys using Omit?
AOmit<Type, 'key1' | 'key2'>
BOmit<Type, 'key1' & 'key2'>
COmit<Type, ['key1', 'key2']>
DOmit<Type, {key1, key2}>
If type A = {x: number; y: string;}, what is Omit<A, 'z'>?
AType with only z property
BError because z does not exist
CType with x and y properties
DType with no properties
Which is true about Omit?
AIt copies all properties
BIt adds new properties to a type
CIt changes property types
DIt removes properties from a type
What is the result of Omit<{a: number; b: string}, 'a'>?
A{a: number; b: string}
B{b: string}
C{}
DError
Explain how the Omit type works and give an example removing a property from a type.
Think about removing keys from an object type.
You got /3 concepts.
    Compare Omit and Pick types and describe when you might use each.
    One removes keys, the other selects keys.
    You got /3 concepts.