TypeScript Flashcards

1
Q
How can you override a constructor in TS? (Hard)
Hint: use class decorators
A
function classDecorator(constructor:T) {
    return class extends constructor {
        newProperty = "new property";
        hello = "override";
    }
}
@classDecorator
class Greeter {
    property = "property";
    hello: string;
    constructor(m: string) {
        this.hello = m;
    }
}

console.log(new Greeter(“world”));

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do you define an interface for a callback in TypeScript when you work with Node.js?

A

interface ICallback {
{ error: Error, result?: number ) : void
});

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Typescript programs are javascript programs: true or false

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is an advantage to provide types annotations?

A

Because they provide intention

How well did you know this?
1
Not at all
2
3
4
5
Perfectly