TypeScript Version: 2.1.4
Code
example
interface IOptions {
option1: string;
option2: string;
option3: string;
}
const DEFAULT_OPTIONS_PRESET: IOptions = {
option1: 'string1',
option2: 'string2',
option3: 'string3'
};
class Options implements IOptions {
public readonly option1: string;
public readonly option2: string;
public readonly option3: string;
constructor (inputOptions: IOptions) {
this = { // The left-hand side of an assignment expression must be a variable or a property access.
...this, // spread types may only be created from object types
...DEFAULT_OPTIONS_PRESET,
...inputOptions
};
const errors = OptionsValidator.validate(this);
if (errors.length) { // ... }
this = { // The left-hand side of an assignment expression must be a variable or a property access.
...this, // spread types may only be created from object types
...OptionsNormalizer.normalize(this)
};
}
}
Expected behavior:
No errors?
With object assign code works well
constructor (inputOptions: IOptions) {
Object.assign(this, DEFAULT_OPTIONS_PRESET, inputOptions);
}
Actual behavior:
Two errors:
The left-hand side of an assignment expression must be a variable or a property access.
Spread types may only be created from object types.
If it's a a correct behaviour please explain me it.
TypeScript Version: 2.1.4
Code
example
Expected behavior:
No errors?
With object assign code works well
Actual behavior:
Two errors:
The left-hand side of an assignment expression must be a variable or a property access.Spread types may only be created from object types.If it's a a correct behaviour please explain me it.