TS2550
Property 'setPrototypeOf' does not exist on type 'ObjectConstructor'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2015' or later.
Broken Code ❌
type HumanHero = typeof human & typeof hero;
const human = {
speak: () => {},
};
const hero = {
fly: () => {},
};
// Prototype-based inheritance
Object.setPrototypeOf(hero, human);{
"compilerOptions": {
"lib": ["dom", "es5"],
"target": "es6"
}
}Fixed Code ✔️
ES5, also known as ECMAScript 2009, doesn't include Object.setPrototypeOf which is why you have to upgrade to ES6 (also known as ES2015):
{
"compilerOptions": {
"lib": ["dom", "es6"],
"target": "es6"
}
}