You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Defining a Stage 3 class property decorator that mutates its class property from data field to a getter/setter field seems to silently fail to mutate the type. The mutation the decorator does is effectively an Object.defineProperty(this, name, {…}) call. The get and set blocks are never called on the instance and inspecting the instance’s getOwnPropertyDescriptor also confirms that no get or set exists on the type.
When running the code with deno run file.ts, the decorator is effectively not applied at all. Compiling the exact same code with tsc and running it with node file.js works as expected.
Preview
exportfunctionInstanceProperty(){returnfunction(_value: unknown,context: ClassFieldDecoratorContext){const{ name }=contextconstdataPropertyName=`__${String(name)}`returnfunction(this: any,initialValue: unknown){this[dataPropertyName]=initialValueObject.defineProperty(this,name,{get(){console.log(`Reading and returning value for property ${String(name)}, ${this[dataPropertyName]}`)returnthis[dataPropertyName]},set(newValue){console.log(`Setting value for property ${String(name)} to ${newValue}`)this[dataPropertyName]=newValue},enumerable: true,configurable: true})returnundefined}}}
Deno 2.2.6
Node 23.6.1
Description
Defining a Stage 3 class property decorator that mutates its class property from data field to a getter/setter field seems to silently fail to mutate the type. The mutation the decorator does is effectively an
Object.defineProperty(this, name, {…})
call. Theget
andset
blocks are never called on the instance and inspecting the instance’sgetOwnPropertyDescriptor
also confirms that noget
orset
exists on the type.When running the code with
deno run file.ts
, the decorator is effectively not applied at all. Compiling the exact same code withtsc
and running it withnode file.js
works as expected.Preview
Reproduction
Here’s a reproduction: https://github.com/augustsaintfreytag/repro-deno-decorators
The text was updated successfully, but these errors were encountered: