TS2550

error 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 ❌

code.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
type HumanHero = typeof human & typeof hero;

const human = {
speak: () => {
}
};

const hero = {
fly: () => {
}
};

// Prototype-based inheritance
Object.setPrototypeOf(hero, human);
tsconfig.json
1
2
3
4
5
6
7
8
9
{
"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):

tsconfig.json
1
2
3
4
5
6
7
8
9
{
"compilerOptions": {
"lib": [
"dom",
"es6"
],
"target": "es6"
}
}