I am currently programming some internal abstract class for project and I need it to be generic (I want it to be extendable).
I want my class to be called as it would extend the T template like Sample extends T
, in order to have all the parameters of T
.
For example if T
is Vue, I would have all Vue parameters such as $el
or $options
without re-declaring Vue nor including it.
So I've got the following :
export namespace SDK {
export abstract class Sample<T> {
private static methods: any = {
hello: Sample.prototype.hello
}
abstract callMe () : void;
x: number = 0
y: number = 0
width: number = 1
height: number = 1
hello (): void {
console.log('Sample hello world')
this.callMe()
}
}
}
But I don't know how to process to include the properties of T into Sample.
I would like it to be like:
export namespace SDK {
export abstract class Sample<T> {
private static methods: any = {
hello: Sample.prototype.hello
}
abstract callMe () : void;
x: number = 0
y: number = 0
width: number = 1
height: number = 1
// T properties (Vue example)
$el: HTMLElement
...
hello (): void {
console.log('Sample hello world')
this.callMe()
}
}
}
I would like my class to be called like:
export default class MyComponent extends SDK.Sample<Vue> {
name: string = 'my-component';
callMe () : void {
console.log('called')
}
mounted () : void {
this.hello()
}
}
I did not find anything about extending from a templated class that allow to have parameters in it.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…