microsoft / microsoft/TypeScript

Erronous documentation for property decorators?

Open
#13,262 7 comments 0 reactions 1 assignee View on GitHub

@rbuckton is already working on this.

Since Jan 4, 2017.

Docs
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

At https://www.typescriptlang.org/docs/handbook/decorators.html

..it reads under "Property Decorators"

If the property decorator returns a value, it will be used as the Property Descriptor for the member.

NOTE  The return value is ignored if your script target is less than ES5.

I'm running a simple example with target ES6

function MyPropDesc() {
  return function (targetProto: Object, propName: string | symbol)   {
    return {
      get: function() { console.log('in getter') }
    }
  }
}

class SomeClass {
  @MyPropDesc()
  someMember;
}

However, this doesn't seem to work. Also, when debugging this, my property decorator is being called from Reflect.js's DecoratePropertyWithoutDescriptor which ignores the result from the descriptor. And...typescript requires the decorator to return void or any. Documentation mistake?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.