Use if (options.numberOfWheels === void 0) { options.numberOfWheels = 4; } if (options.numberOfWheels === void 0) { options.numberOfWheels = 4; } instead. (Otherwise, 0 or NaN ... will also be 4)
In addition, what you do is actually quite smart, and this is the best you can do. Such things will not work:
constructor (options: {color: number, numberOfWheels?: number} = {color: options.color})
source share