-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issue
Milestone
Description
TypeScript Version: 2.1.5
SUGGESTION: It seems to be no way to define extending for a class
Code
class Classic {
}
// some global object literal containing methods
declare window.somePOJO: { [key: string]: Function };
// dirty inheritance of POJO
Object.assign(Classic.prototype, window.somePOJO);Question: How tot tell TS, that Classic is extended (has new methods)?
Attempt 1 -- Interface
class Classic ...
object.Assign(...
// declare inherited methods in interface of Classic
interface Classic {
inheritedMethod(): void;
}
// but then in subClass
class SubClassic extends Classic {
inheritedMethod() {
super.inheritedMethod(); // Error TS2340´
// Only public and protected methods of the base class are accessible via the 'super'
}
}Attempt 2 -- Declare POJO as base class
// all methods of POJO in declared class
declare class somePOJO {
public inheritedMethod(): void;
}
class Classic extends somePOJO {
constructor() {
// Error TS17009
// 'super' must be called before accessing 'this' in the constructor of a derived class.
// But super on POJO fails
}
}I searched hard in documentation and asked on StackOverflow, but defining extensions for class seems to be currently unsupported.
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issue