microsoft / microsoft/TypeScript
Provide a `this` type for `get`/`set` methods in `Reflect.defineProperty` options
Open
Nobody has claimed this yet.
Experience Enhancement
Suggestion
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
Code
var A: {a?: number, b: number} = {b:2}
Reflect.defineProperty(A, 'a', {
// set(this: any, value: any) { // to fix
set(value: any) {
console.log(this.b); // Property 'b' does not exist on type 'PropertyDescriptor'.
},
enumerable: true,
configurable: true
});
A.a = 1;
// expect the context of setter is A
Expected behavior:
expect the context of the setter is A
Actual behavior:
Property 'b' does not exist on type 'PropertyDescriptor'.
Playground Link:
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked TypeScript Playground example and compare the setter's inferred this with the expected receiver type. Trace the Reflect.defineProperty options and PropertyDescriptor typings, then add coverage for the example in an appropriate existing test area. Done means the setter context is typed as the target object without the reported error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100