0
0
Typescriptprogramming~10 mins

Omit 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 omit the 'age' property from the Person type.

Typescript
type Person = { name: string; age: number; city: string };
type PersonWithoutAge = Omit<Person, [1]>;
Drag options to blanks, or click blank then click option'
A'age'
B'name'
C'city'
D'gender'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to put the property name in quotes.
Trying to omit a property that does not exist.
2fill in blank
medium

Complete the code to create a type without 'email' and 'phone' properties.

Typescript
type Contact = { email: string; phone: string; address: string };
type ContactInfo = Omit<Contact, [1]>;
Drag options to blanks, or click blank then click option'
A'email'
B'email' | 'phone'
C'phone'
D'address'
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting only one property at a time.
Not using quotes around property names.
3fill in blank
hard

Fix the error in the code to omit the 'id' property from the User type.

Typescript
type User = { id: number; username: string; password: string };
type UserWithoutId = Omit<User, [1]>;
Drag options to blanks, or click blank then click option'
Aid
B['id']
C"id"
D'id'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the property name without quotes.
Using an array instead of a union of string literals.
4fill in blank
hard

Fill both blanks to create a type that omits 'title' and 'year' from Movie.

Typescript
type Movie = { title: string; year: number; director: string };
type MovieSummary = Omit<Movie, [1] [2] [3]>;
Drag options to blanks, or click blank then click option'
A'title'
B|
C'year'
D&
Attempts:
3 left
💡 Hint
Common Mistakes
Using & instead of | to separate keys.
Not quoting the property names.
5fill in blank
hard

Fill all three blanks to omit 'street', 'city', and 'zip' from Address.

Typescript
type Address = { street: string; city: string; zip: string; country: string };
type SimpleAddress = Omit<Address, [1] [2] [3]>;
Drag options to blanks, or click blank then click option'
A'street'
B|
C'city'
D'zip'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to include all properties to omit.
Using wrong separators like & or commas.