microsoft / microsoft/TypeScript
No warning for a class implementing itself
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.4k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
Bug Report
🔎 Search Terms
[implements itself, self implements]
🕗 Version & Regression Information
- This is the behavior in every version I tried from 3.3 on, and I reviewed the FAQ for entries about inheritance.
⏯ Playground Link
Playground link with relevant code
💻 Code
class Foo implements Foo {}
🙁 Actual behavior
This code passed typechecking.
🙂 Expected behavior
I expected the TypeScript compiler to emit an error on this code.
As far as I know, it's a no-op for a class to implement itself. The code author very likely intended to write something else.
This came up in the wild in TypeScript inside Google's repo. A file was trying to create a fake version of MediaSession with export class MediaSession implements MediaSession { for testing. The class accidentally implemented itself instead of the MediaSession interface from https://github.com/DefinitelyTyped/DefinitelyTyped/blob/c6f1fc8c0b7c2ebe8e099586af618b0a33cfef65/types/wicg-mediasession/index.d.ts#L20.
Another example found via Google: https://stackoverflow.com/questions/54306190/what-does-it-mean-when-a-class-implements-itself-in-typescript
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
Reproduce the issue from the linked TypeScript Playground using class Foo implements Foo {} and inspect how the compiler handles the implements clause. Add a regression test for the self-implementation case and verify that typechecking emits an error while valid implements clauses remain unaffected.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100