让打字稿编译器忽略一行或接受错误声明的函数 (tsx)

Getting typescript compiler to ignore a line or accept an incorrectly declared function (tsx)

我有一个测试要 运行,它会检查以确保传递了正确的参数。但是我的实际文件已经有正确的声明,所以它不允许我编译。我试过使用 // @ts-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);
});

"hack"就是把它转换成any

new CurvedMeter(badProps as any)