I have the following piece of code:
interface User {
id: number;
name: string;
}
const newUser = {id: 5, name: "Tom", age: 22}
// throws no error
const user1: User = newUser
// throws:
// Type '{ id: number; name: string; age: number; }' is not assignable to type 'User'.
// Object literal may only specify known properties, and 'age' does not exist in type 'User'.
const user2: User = {id: 5, name: "Tom", age: 22}
Why is the first assignment ok and the second one not, even though they do pretty much the same thing?