0
0
Typescriptprogramming~10 mins

How intersection combines types in Typescript - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
A^
B&
C+
D|
Attempts:
3 left
💡 Hint
Common Mistakes
Using union operator '|' instead of intersection '&'.
2fill in blank
medium

Complete 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'
AA | B
BA + B
CA & B
DA ^ B
Attempts:
3 left
💡 Hint
Common Mistakes
Using union '|' which allows either type but not both.
3fill in blank
hard

Fix 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'
A&
B+
C|
D-
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' or '-' which are invalid for types.
4fill in blank
hard

Fill 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'
AType1
BType2
CType3
DType4
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing types that don't exist or using wrong operators.
5fill in blank
hard

Fill 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'
AAlpha
BBeta
CGamma
DDelta
Attempts:
3 left
💡 Hint
Common Mistakes
Using types that don't cover all required properties.