microsoft / microsoft/TypeScript

No warning for a class implementing itself

Open
#45,806 0 comments 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Awaiting More Feedback Suggestion
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

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

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.