microsoft / microsoft/TypeScript

Proposal: allow ambient property declarations to override accessors as well

Open
#40,220 3 comments 19 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Currently, this pattern gives an error, but arguably shouldn't:

class B {
  get p() { return B.s } // inferred p: {}
  static get s() { return {} }
}
class C extends B {
  declare readonly p: { x: 1 }
}

Expected behavior:

No error, and C.p: { x: 1 } (but is still an accessor for emit and checking purposes). That is, this should be legal:

class D extends C {
  get p() { return { x: 1 } as const }
}

Actual behavior:

Error, and C.p is a property, not an accessor.

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.

Research direction

Start by reproducing the class examples in the issue and compare the current diagnostic with the expected behavior. The change is complete when the ambient declaration can override the inherited accessor without an error, C.p has the declared type, and D can still declare the accessor shown.

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
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.