将使用@Input()传递的对象转换为打字稿中的接口类型

时间:2020-05-04 04:48:04

标签: angular typescript data-sharing

我想使用@Input()将对象从父组件传递到子组件,并在子组件中将其强制转换为接口。 界面定义

    export interface IDummy {
    name: string;
    issueNumber: number;
    }

在我的parent.component.ts

    dummyVariable = {"name":"typescript","issue":"problem with casting objects to an interface using Input"};

在我的parent.component.html

    <child-component [dummyVariable]="dummyVariable"></child-component>

在我的child.component.ts

    @Input() dummyVariable:IDummy;//it should throw an error saying that it is missing an interface property issueNumber, but it runs successfully without throwing an error.

我做错了什么?

0 个答案:

没有答案