Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to define a type that combines properties of A and B.
Typescript
type AB = A [1] B; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using union operator '|' instead of intersection '&'.
✗ Incorrect
The intersection operator & combines types by including all properties from both types.
2fill in blank
mediumComplete the code to create a variable with type that has both name and age properties.
Typescript
const person: [1] = { name: 'Alice', age: 30 };
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using union '|' which allows either type but not both.
✗ Incorrect
Using & creates a type with all properties from both A and B.
3fill in blank
hardFix the error in the type intersection to correctly combine types X and Y.
Typescript
type XY = X [1] Y; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' or '-' which are invalid for types.
✗ Incorrect
The correct operator to combine types by intersection is &.
4fill in blank
hardFill both blanks to create a type that combines properties and a variable of that type.
Typescript
type Combined = [1] & [2]; const obj: Combined = { id: 1, label: 'Item' };
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing types that don't exist or using wrong operators.
✗ Incorrect
We combine Type1 and Type2 using & to get all properties.
5fill in blank
hardFill all three blanks to create an intersection type and a variable with all properties.
Typescript
type Full = [1] & [2] & [3]; const fullObj: Full = { a: 1, b: 'text', c: true };
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using types that don't cover all required properties.
✗ Incorrect
The intersection of Delta, Beta, and Gamma includes all their properties.