Closed
Description
TypeScript Version: 3.8.0-dev.20191113
Search Terms:
decorators, useDefineForClassFields, useDefineForClassFields decorators bug
Code
function Decorator() {
return function (target, propKey, descriptor) {
const symbol = Symbol();
target.constructor.prototype[symbol] = descriptor ? typeof descriptor.initializer !== 'undefined' ? descriptor.initializer() : undefined : undefined;
return {
configurable: true,
enumerable: true,
set(value) {
this[symbol] = value;
},
get() {
return this[symbol] + 'decorated';
}
}
}
}
class TestTSDefine {
@Decorator()
myProp = "test";
}
console.log(new TestTSDefine().myProp);
Expected behavior:
output should be 'testdecorated'
Actual behavior:
output is 'test'
Use the same code with "useDefineForClassFields = false"
output is the expected 'testdecorated'
with babel (also [[Define]] behaviour) everything works.
** Repository to reproduce with Babel and Typescript **: https://github.com/mzeiher/decorator-ts-define-bug (see README)