#The documentation for the decorator seems to be different from the actual situation I encountered

1 messages · Page 1 of 1 (latest)

sudden mangoBOT
#
farad314#0

Preview:```ts
function test(...args: unknown[]) {
console.log(args)
}

//@EnforceFinalMethods
class foo {
@test
bar() {}
}```

obtuse timber
# sudden mango

These code generates this

[
  λ bar(),
  {
    kind: "method", 
    name: "bar",
    static: false,
    private: false,
    access: {
      has: λ, 
      get: λ
    }, 
    metadata: undefined, 
    addInitializer: λ 
  }
]
#

in documents it seems like I need to write things like this:

<T>(
  target: Object,
  methodName: string | symbol,
  propertyDescriptor: TypedPropertyDescriptor<T>
) => TypedPropertyDescriptor<T> | void
obtuse timber
#

This is what I got when I click "Go to Definition" in context menu

// lib.es5.d.ts
interface TypedPropertyDescriptor<T> {
    enumerable?: boolean;
    configurable?: boolean;
    writable?: boolean;
    value?: T;
    get?: () => T;
    set?: (value: T) => void;
}
#

Which is also nothing like I got

#

I think the most likely reason is that I misunderstood the information provided in the document to some extent.

#

So where should I look for the correct information?

obtuse timber
#

!helper

steady stratus
#

Have you enabled experimentalDecorators?

To enable experimental support for decorators, you must enable the experimentalDecorators compiler option either on the command line or in your tsconfig.json:

#

its been a while since I used decorators, but there used to be a different specification about how decorators would work.
Enabling it, gives a different output in the playground

wise mantle
#

This is also a good guide to modern, standard decorators: https://2ality.com/2022/10/javascript-decorators.html

obtuse timber
#

Anyway, now I know what happening, thanks for your help

#

and

#

is there something like mdn or other documents for this? I am not a native English speaker and it is a little too hard for me to extract the information I need from a blog

#

!resolved

wise mantle
#

experimentalDecorators opts in to the old, legacy version of decorators.

wise mantle
#

I'm not finding any MDN documentation - but it's technically still an "in-progress" language feature that is not supported in browsers yet.

obtuse timber
#

I know what "stage 3" means

#

so

#

Actually

wise mantle
obtuse timber
#

oh

#

I think that's what I need