You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Funny thing is, if I don't use <T> and instead use a realized type like {foo: string}, it doesn't complain about "A class may only implement another class or interface.", and still infers the type correctly in the extending class.
There's an inconsistency here, and I'm not sure which of the conflicting errors is the semantically correct one.
The text was updated successfully, but these errors were encountered:
I think this is working as intended. You can't implement a type parameter, so foo is just seen as a new method, not as an implementation of an interface. You can, however, have a property that is a type parameter, so we will still correctly give an error when using the actions property incorrectly. We're giving you the error on the call to actions.foo, not the foo in MyMobxAdaptor2 -- and as far as the compiler is concerned, these are two completely unrelated methods that happen to share a name.
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.
TypeScript Version: 2.7.2
Search Terms:
typescript extend generic type
A class may only implement another class or interface.
Code
Expected behavior:
One of:
Adaptor<T>
not being an interface, and don't understand thatfoo()
is not implemented correctlyAdaptor<T>
correctly, and emit an error forfoo()
not being implemented correctly.Actual behavior:
Error is emitted for both
Adaptor<T>
not being an interface, andfoo()
not being implemented correctly.This implies that even though TypeScript emits an error, it does manage to use the generic correctly.
Playground Link:
Click me
Related Issues:
Funny thing is, if I don't use
<T>
and instead use a realized type like{foo: string}
, it doesn't complain about "A class may only implement another class or interface.", and still infers the type correctly in the extending class.There's an inconsistency here, and I'm not sure which of the conflicting errors is the semantically correct one.
The text was updated successfully, but these errors were encountered: