microsoft / microsoft/TypeScript

Erronous documentation for property decorators?

Đang mở
#13,262 7 bình luận 0 reaction 1 người được giao Xem trên GitHub

@rbuckton đang làm issue này rồi.

Từ ngày 4/1/2017.

Docs
Ngôn ngữ chính
Go
Star
111k
Fork
14.3k
Merge trung bình
2 ngày 4 giờ
Pull request đã merge (30 ngày)
132

Mô tả

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?

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.