Friday, December 7, 2018

optional properties at constructor signatures in TypeScript

You may call this constructor with either one or two things. Get it?

constructor(foo:string, averager = new AverageSizeAverager()) {

 
 

The Optional decorator of Angular lets this happen too like so:

constructor(foo:string, @Optional() averager: AverageSizeAverager) {

 
 

Do note that these two things have two different states if the second variable goes unset.

No comments:

Post a Comment