No warning for a class implementing itself #45806
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
Bug Report
π Search Terms
[implements itself, self implements]
π Version & Regression Information
β― Playground Link
Playground link with relevant code
π» Code
π 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
withexport class MediaSession implements MediaSession {
for testing. The class accidentally implemented itself instead of theMediaSession
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
The text was updated successfully, but these errors were encountered: