2021-05-03 19:29:22 +02:00
|
|
|
import {Type} from "./Utils.js";
|
2020-09-25 22:03:22 +02:00
|
|
|
|
|
|
|
export default interface Extendable<ComponentClass> {
|
|
|
|
as<C extends ComponentClass>(type: Type<C>): C;
|
|
|
|
|
|
|
|
asOptional<C extends ComponentClass>(type: Type<C>): C | null;
|
2021-05-13 15:58:41 +02:00
|
|
|
|
|
|
|
has<C extends ComponentClass>(type: Type<C>): boolean;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @throws MissingComponentError
|
|
|
|
*/
|
|
|
|
require<C extends ComponentClass>(type: Type<C>): void;
|
|
|
|
}
|
|
|
|
|
|
|
|
export class MissingComponentError<ComponentClass> extends Error {
|
|
|
|
public constructor(type: Type<ComponentClass>) {
|
|
|
|
super(`Required component ${type.name} was not found.`);
|
|
|
|
}
|
2020-09-25 23:42:15 +02:00
|
|
|
}
|