TypeScript Decorators Quiz
A 35-question TypeScript quiz covering decorator fundamentals, class decorators, method and property decorators, decorator factories, metadata reflection, and execution order.
Question 1
Decorators can be applied to:
Question 2
Which config flag must be enabled to use decorators?
Question 3
A decorator is:
Question 4
What does the decorator receive?
function Log(target: Function) {}
@Log
class Box {}Question 5
Class decorators can:
Question 6
When does this run?
@Log
class App {}
function Log(constructor: Function) { console.log('run'); }Question 7
A decorator factory is:
Question 8
What prints first?
function Tag(name: string) {
return function(target: Function) {
console.log('decorator');
};
}
@Tag('box')
class Box {}Question 9
Decorator factories are useful for:
Question 10
What does a method decorator receive?
class A {
@Dec
run() {}
}
function Dec(target: any, key: string, desc: PropertyDescriptor) {}Question 11
Method decorators can:
Question 12
Property decorators receive:
class P { @Label name: string; }
function Label(target: any, key: string) {}Question 13
Property decorators cannot:
Question 14
What does a parameter decorator receive?
class C {
run(@Info id: number) {}
}
function Info(target: any, key: string, index: number) {}Question 15
Parameter decorators are often used for:
Question 16
Decorator expression evaluation runs:
Question 17
Decorator application order is:
Question 18
In what order do these apply?
@A
@B
class X {}Question 19
design:type metadata applies to:
import 'reflect-metadata';
class T {
@Reflective
name: string;
}Question 20
Metadata reflection requires:
Question 21
Why might this decorator fail?
function Make(target: any, key: string) {
target[key] = 10;
}Question 22
Decorators are applied:
Question 23
What does returning a function from a decorator factory allow?
function Flag(x: boolean) {
return function(constructor: Function) {};
}Question 24
Decorators cannot:
Question 25
Where does this decorator attach?
class Car {
@Meta
speed = 10;
}Question 26
Decorators can be composed by:
Question 27
Decorators are most commonly used for:
Question 28
Decorators cannot be applied to:
Question 29
Returning a new constructor from a class decorator:
Question 30
Decorator factories allow:
Question 31
Decorators run during:
Question 32
Decorators are enabled by:
Question 33
Decorators cannot:
Question 34
Decorator metadata helps:
Question 35
Overall, decorators enable developers to:
