mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[FIX] typing: Component class should be generic on Props and Env
Otherwise, it prevents proper typing with typescript
This commit is contained in:
committed by
Samuel Degueldre
parent
07d34248ae
commit
6a15874d23
@@ -1,19 +1,18 @@
|
|||||||
import type { Env } from "../app/app";
|
|
||||||
import type { ComponentNode } from "./component_node";
|
import type { ComponentNode } from "./component_node";
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Component Class
|
// Component Class
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
export class Component {
|
export class Component<Props = any, Env = any> {
|
||||||
static template: string = "";
|
static template: string = "";
|
||||||
static props?: any;
|
static props?: any;
|
||||||
|
|
||||||
props: any;
|
props: Props;
|
||||||
env: Env;
|
env: Env;
|
||||||
__owl__: ComponentNode;
|
__owl__: ComponentNode;
|
||||||
|
|
||||||
constructor(props: any, env: Env, node: ComponentNode) {
|
constructor(props: Props, env: Env, node: ComponentNode) {
|
||||||
this.props = props;
|
this.props = props;
|
||||||
this.env = env;
|
this.env = env;
|
||||||
this.__owl__ = node;
|
this.__owl__ = node;
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ exports[`t-props t-props with props 1`] = `
|
|||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
let b2 = component(\`Child\`, Object.assign({}, ctx['props'], {a: 1,b: 2}), key + \`__1\`, node, ctx);
|
let b2 = component(\`Child\`, Object.assign({}, ctx['childProps'], {a: 1,b: 2}), key + \`__1\`, node, ctx);
|
||||||
return block1([], [b2]);
|
return block1([], [b2]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
|
|||||||
@@ -95,12 +95,12 @@ describe("t-props", () => {
|
|||||||
class Parent extends Component {
|
class Parent extends Component {
|
||||||
static template = xml`
|
static template = xml`
|
||||||
<div>
|
<div>
|
||||||
<Child t-props="props" a="1" b="2" />
|
<Child t-props="childProps" a="1" b="2" />
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
static components = { Child };
|
static components = { Child };
|
||||||
|
|
||||||
props = { a: "a", c: "c" };
|
childProps = { a: "a", c: "c" };
|
||||||
}
|
}
|
||||||
|
|
||||||
await mount(Parent, fixture);
|
await mount(Parent, fixture);
|
||||||
|
|||||||
Reference in New Issue
Block a user