Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a variable with an intersection type of Person and Employee.
Typescript
type Person = { name: string };
type Employee = { id: number };
let worker: Person [1] Employee; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '|' instead of '&' which creates a union type.
Using ',' or '+' which are invalid in type declarations.
✗ Incorrect
The intersection type uses the '&' symbol to combine types so the variable has all properties.
2fill in blank
mediumComplete the code to define a function parameter with an intersection type of A and B.
Typescript
type A = { a: number };
type B = { b: string };
function combine(param: A [1] B) {
console.log(param.a, param.b);
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '|' which allows either type but not both.
Using invalid symbols like '/' or '+'.
✗ Incorrect
The function parameter uses '&' to require both A and B properties.
3fill in blank
hardFix the error in the intersection type declaration.
Typescript
type X = { x: number } [1] { y: string }; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '|' which creates a union type.
Using ',' or '+' which are invalid here.
✗ Incorrect
The correct intersection operator is '&' to combine the two object types.
4fill in blank
hardFill both blanks to create an intersection type combining interfaces A and B.
Typescript
interface A { a: number; }
interface B { b: string; }
type AB = [1] A [2] B; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'interface' instead of 'type' for intersection types.
Using '|' instead of '&' to combine types.
✗ Incorrect
Use 'type' to declare a type alias and '&' to combine interfaces A and B.
5fill in blank
hardFill all three blanks to create a variable with an intersection type and assign a valid object.
Typescript
type C = { c: boolean };
type D = { d: number };
let obj: [1] = { c: true, d: 42 } as [2] [3] D; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using only one type without intersection.
Using '|' instead of '&' for intersection.
✗ Incorrect
The variable obj is declared with type 'C & D' and cast as 'C & D' to satisfy both types.