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
/* taken from mongoose.Document */interfaceDocument{increment(): this;}/* our custom model extends the mongoose document */interfaceCustomDocumentextendsDocument{}exportclassExample<ZextendsCustomDocument>{constructor(){// types of increment not compatible??this.test<Z>();}publictest<ZextendsDocument>(){}}
Expected behavior:
The type parameter Z should be assignable to the method test as Z is a subtype of CustomDocument which is a subtype of Document.
Actual behavior:
Polymorphic this somehow breaks the functionality.
TS-Error:
error TS2344: Type 'Z' does not satisfy the constraint 'Document'.
Type 'CustomDocument' is not assignable to type 'Document'.
Types of property 'increment' are incompatible.
Type '() => CustomDocument' is not assignable to type '() => Z'.
Type 'CustomDocument' is not assignable to type 'Z'.
TypeScript Version: 2.9.0-dev.20180515
Search Terms: generics, property, incompatible, polymorphic this, extends constraint
Code
Expected behavior:
The type parameter Z should be assignable to the method
test
as Z is a subtype of CustomDocument which is a subtype of Document.Actual behavior:
Polymorphic this somehow breaks the functionality.
TS-Error:
Playground Link: typescriptlang playground
Related Issues: maybe #17316? or #7818?
The text was updated successfully, but these errors were encountered: