I expect the following code to not compile. The reason is that when assigning person
and expert
to people
, the person
constant satisfies the type for the people
constant which should be Person
type. However, the expert
has a skills
filed that doesn't exist on Person
type.
Yet it does compile.
interface Person {
name: string;
age?: number;
}
interface Developer {
name: string;
age?: number;
skills: string[];
}
const person: Person = {
name: 'john doe',
age: 20,
};
const expert: Developer = {
name: 'jane doe',
skills: ['javascript', 'react']
};
const people: Person[] = [ person, expert ];
console.log(people);