From 99b5e9ec555a8e9436d919d8a150792c4583886f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Mon, 17 Jan 2022 10:18:45 +0100 Subject: [PATCH] [FIX] typing: Component class should be generic on Props and Env Otherwise, it prevents proper typing with typescript --- src/component/component.ts | 7 +++---- tests/components/__snapshots__/t_props.test.ts.snap | 2 +- tests/components/t_props.test.ts | 4 ++-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/component/component.ts b/src/component/component.ts index 0caad653..36bfbe82 100644 --- a/src/component/component.ts +++ b/src/component/component.ts @@ -1,19 +1,18 @@ -import type { Env } from "../app/app"; import type { ComponentNode } from "./component_node"; // ----------------------------------------------------------------------------- // Component Class // ----------------------------------------------------------------------------- -export class Component { +export class Component { static template: string = ""; static props?: any; - props: any; + props: Props; env: Env; __owl__: ComponentNode; - constructor(props: any, env: Env, node: ComponentNode) { + constructor(props: Props, env: Env, node: ComponentNode) { this.props = props; this.env = env; this.__owl__ = node; diff --git a/tests/components/__snapshots__/t_props.test.ts.snap b/tests/components/__snapshots__/t_props.test.ts.snap index 2d8397fa..fff360b7 100644 --- a/tests/components/__snapshots__/t_props.test.ts.snap +++ b/tests/components/__snapshots__/t_props.test.ts.snap @@ -93,7 +93,7 @@ exports[`t-props t-props with props 1`] = ` let block1 = createBlock(\`
\`); 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]); } }" diff --git a/tests/components/t_props.test.ts b/tests/components/t_props.test.ts index ce78d09b..1210a66e 100644 --- a/tests/components/t_props.test.ts +++ b/tests/components/t_props.test.ts @@ -95,12 +95,12 @@ describe("t-props", () => { class Parent extends Component { static template = xml`
- +
`; static components = { Child }; - props = { a: "a", c: "c" }; + childProps = { a: "a", c: "c" }; } await mount(Parent, fixture);