Arrays typescript不';t在错误类型的数组推送上抛出typeerror

Arrays typescript不';t在错误类型的数组推送上抛出typeerror,arrays,typescript,Arrays,Typescript,如我所料,以下代码不可传输 interface Interface1 { a: number; b: number; } const arr: Array<Interface1> = [] arr.push({ a: 1, b: 1, c: 1 }) 发生了什么,我如何才能成功地在这个错误的数组推送上抛出typeError 复制链接:这被调用,它的工作方式正是这样。检查“新鲜”对象文字的额外属性。“非新”对象文字(已分配给变量的文字)不可

如我所料,以下代码不可传输

interface Interface1 {
    a: number;
    b: number;
}

const arr: Array<Interface1> = []

arr.push({
    a: 1,
    b: 1,
    c: 1
})
发生了什么,我如何才能成功地在这个错误的数组推送上抛出typeError

复制链接:

这被调用,它的工作方式正是这样。检查“新鲜”对象文字的额外属性。“非新”对象文字(已分配给变量的文字)不可用。可能存在重复的
interface Interface2 {
    a: number;
    b: number;
    c: number;
}

const test: Interface2 = {
    a: 1,
    b: 1,
    c: 1
}

arr.push(test)