有趣的行为:对象文字只能指定已知属性

这里有类似的问题,我可以理解此错误的性质:

type Person = { name: string };

// Error: Object literal may only specify known properties, and 'age' does not exist in type 'Person'.
const person: Person = { name: 'Sarah', age: 13 };

So this fails, because property age is not a part of type Person which makes sense.

但是,我可以做到这一点而没有任何问题:

type Person = { name: string };

const obj = { name: 'Sarah', age: 13 };
const person: Person = obj;

console.log(person); // { name: 'Sarah', age: 13 }

为什么第一个失败,第二个失败-这两个示例都不都失败还是都通过?

对于我来说,这两个代码段是相同的。不是吗