Conditional statements in constructor could prevent property definitions

Topics: General
Nov 6, 2012 at 4:41 PM

Hi, here is an example that demonstrates the problem:


"use strict";

class Surly {
	private grumble: string;
	constructor (message: string) {
			this.grumble = message;
		this.grumble = message;

var surly = new Surly(undefined);


surly.update("Cheer up, sausage!"); // Can't add property grumble, object is not extensible 


It does not seem correct from a reading of the Surly class that the property grumble would not exist at runtime.

Of course this can be easily fixed by setting:

private grumble = undefined;

But then we are requiring further discipline on the part of the developer.



Nov 7, 2012 at 2:26 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.