made rungs generic

This commit is contained in:
Daniel Ledda
2023-01-03 12:04:30 +01:00
parent a495ca025e
commit 98da168a6a

View File

@@ -2,12 +2,12 @@ import {SubNode} from "./helpers";
export type RungOptions = {}; export type RungOptions = {};
export default abstract class Rung { export default abstract class Rung<NodeType extends Node = Node> {
protected node: Node | null = null; protected node: NodeType | null = null;
protected constructor(options: RungOptions) {} protected constructor(options: RungOptions) {}
render(): Node { render(): NodeType {
if (!this.node) { if (!this.node) {
this.node = this.build(); this.node = this.build();
} }
@@ -28,7 +28,7 @@ export default abstract class Rung {
} }
} }
protected abstract build(): Node; protected abstract build(): NodeType;
} }
export type FunctionalRung<Props extends Record<string, any>, N extends HTMLElement> = (attributes: Props, subNodes?: SubNode[]) => N; export type FunctionalRung<Props extends Record<string, any>, N extends Node = Node> = (attributes: Props, subNodes?: SubNode[]) => N;