interface IConfig1 {
name: string,
age: string
}
interface IConfig2 {
name: string
}
const config1: IConfig1 = {
name: "123",
age: "123"
}
var config2: IConfig2 = {
// Type '{ age: string; name: string; }' is not assignable to type 'IConfig2'.
// Object literal may only specify known properties, and 'age' does not exist in type 'IConfig2'.(2322)
age: "123",
name: "123"
}
// Why no error
var config3: IConfig2 = config1
Defining the config2 object throws an error because the age does not exist in type IConfig2. But what confuses me is why config3 don't throw the error 'age' does not exist in type 'IConfig2'.
How to fix it? make config3 throw the error.
Object literalonly looks for excess properties