Files
owl/src/component/component.ts
T
Lucas Lefèvre 5c71744e19 [IMP] component: display nice error for wrong child component
If you declare a child component which is not actually a Component,
the error message is not very friendly and not very helpfull to find
what happens and which child component is wrong.

```
const ChildComponent = "not a component constructor";

class MyComponent extends Component {
    static components = { ChildComponent };
}
```

This commit improves the type declaration for those working with Typescript
and adds a runtime check for javascript codebases
2022-05-06 17:09:30 +02:00

44 lines
1.0 KiB
TypeScript

import type { ComponentNode } from "./component_node";
// -----------------------------------------------------------------------------
// Component Class
// -----------------------------------------------------------------------------
type Props = { [key: string]: any };
interface StaticComponentProperties {
template: string;
defaultProps?: any;
props?: any;
components?: { [componentName: string]: ComponentConstructor };
}
export type ComponentConstructor<P extends Props = any, E = any> = (new (
props: P,
env: E,
node: ComponentNode
) => Component<P, E>) &
StaticComponentProperties;
export class Component<Props = any, Env = any> {
static template: string = "";
static props?: any;
static defaultProps?: any;
props: Props;
env: Env;
__owl__: ComponentNode;
constructor(props: Props, env: Env, node: ComponentNode) {
this.props = props;
this.env = env;
this.__owl__ = node;
}
setup() {}
render(deep: boolean = false) {
this.__owl__.render(deep === true);
}
}