Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No warning for a class implementing itself #45806

Open
lauraharker opened this issue Sep 9, 2021 · 0 comments
Open

No warning for a class implementing itself #45806

lauraharker opened this issue Sep 9, 2021 · 0 comments
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript

Comments

@lauraharker
Copy link

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

@andrewbranch andrewbranch added Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript labels Sep 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

2 participants