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”));
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
});
3
Q
Typescript programs are javascript programs: true or false
A
True
4
Q
What is an advantage to provide types annotations?
A
Because they provide intention