Unit testing 让typescript编译器忽略一行或接受声明错误的函数(tsx)

Unit testing 让typescript编译器忽略一行或接受声明错误的函数(tsx),unit-testing,typescript,compiler-errors,tsx,Unit Testing,Typescript,Compiler Errors,Tsx,我想运行一个测试,检查以确保传入正确的参数。但是我的实际文件已经有了正确的声明,所以它不允许我编译。我试图使用/@ts ignoreignore注释,但它不起作用。我如何让它忽略这个错误 在我的实际文件中,声明: interface Props { maxValue: number; fill?: string; value: number; width: number; height: number; } new CurvedMeter(props: P

我想运行一个测试,检查以确保传入正确的参数。但是我的实际文件已经有了正确的声明,所以它不允许我编译。我试图使用
/@ts ignore
ignore注释,但它不起作用。我如何让它忽略这个错误

在我的实际文件中,声明:

interface Props {
    maxValue: number;
    fill?: string;
    value: number;
    width: number;
    height: number;
}
new CurvedMeter(props: Props) //how it is declared
在我的测试文件中:

it('throws if any neccesary props are missing', () => {
    const badProps = { maxValue: 100, value: 10, width: 100 };
    new CurvedMeter(badProps); // @ts-ignore <- does not work
    expect.any(Error);
});
it('如果缺少任何必要的道具就会抛出',()=>{
const badProps={maxValue:100,value:10,width:100};
新的CurvedMeter(badProps);/@ts ignore这个“黑客”将它转换为
any

new CurvedMeter(badProps as any)

为什么不将这些道具声明为可选的呢?@toskv在我的web应用程序中,它们是必要的,我觉得为了测试而更改我的声明是不符合目的的。此测试旨在检查我是否有
maxValue
value
width
height
,否则会抛出错误,但错误是必要的这是不成熟的,会阻止我运行我的web应用程序。你可以在测试中创建一个存根,扩展CurvedMeter并发送一些默认或空参数。@toskv我已经包含了一个测试,ts不会编译它。希望现在可以理解,我根本不想更改我的声明。所以..你的问题是badProps不是道具类型?太好了!非常好用