Fix Error TS2550: Property ‘includes’ Does Not Exist on Type ‘string’

Error TS2550 “Property ‘includes’ does not exist on type ‘string'” means your lib setting is older than ES2015, so TypeScript doesn’t know String.prototype.includes exists. Fix it in tsconfig.json by setting lib (or target) to es2015 or later, such as:

"compilerOptions": { "target": "es2024", "lib": ["es2024", "dom"] }

These errors come straight from TypeScript 7.0.2 and Node.js v22.22.2. A few of the messages changed in TypeScript 7, so the exact wording below may differ from older posts.

You’ll see the error for strings and for arrays, why an explicit lib overrides your target, the tsconfig fix, TypeScript 7 rejecting –target es5, and an indexOf fallback.

Reproduce error TS2550 for string includes

The error appears when the compiler only loads the ES5 library, where strings have no includes(). The message even tells you which lib adds it:

declare const console: { log(...args: unknown[]): void };   // stands in for @types/node or the dom lib

const city: string = "San Antonio";
console.log(city.includes("Antonio"));

Output:

search_es5.ts(4,18): error TS2550: Property 'includes' does not exist on type 'string'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2015' or later.
Command Prompt showing TypeScript error TS2550 property includes does not exist on type string with lib es5
With –lib es5, TypeScript reports TS2550 and suggests changing the lib compiler option to es2015 or later.

includes() itself is plain string searching; the alternatives are in checking if a string contains a substring in TypeScript.

Why does includes fail on an array with lib es2015?

Array.prototype.includes arrived one version later, in ES2016. So a project on ES2015 compiles string checks but fails on arrays:

const states: string[] = ["TX", "CA", "NY"];
console.log(states.includes("TX"));

Output:

states.ts(2,20): error TS2550: Property 'includes' does not exist on type 'string[]'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2016' or later.
Command Prompt showing TypeScript TS2550 property includes does not exist on type string array, change lib to es2016
The same TS2550 error names string[] this time and asks for es2016 or later.

The array version is how you’d check membership; more options are in checking if a value exists in an array in TypeScript.

Why does lib override target in tsconfig.json?

If you leave out lib, TypeScript picks one that matches target. Once you list lib yourself, that list is all you get. Old projects often still say ["es5", "dom"]:

{
  "compilerOptions": {
    "target": "es2015",
    "lib": ["es5", "dom"],
    "strict": true
  },
  "files": ["search.ts"]
}

Output:

search.ts(5,20): error TS2550: Property 'includes' does not exist on type 'string[]'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2016' or later.
Command Prompt showing tsc -p with a legacy tsconfig lib es5 and dom producing TS2550 for an array includes call
With target es2015 but lib es5 and dom, the string check compiles and the array includes call still fails with TS2550.

In my run, adding dom was enough for the string method, but not for the array one. Don’t rely on that: list the ES version you actually target. Newer Intl date options depend on lib too, as in formatting dates in TypeScript.

Fix TS2550 by updating lib in tsconfig.json

Set lib to the same year as your target, plus dom for browser code. Then both calls compile and run:

{
  "compilerOptions": {
    "target": "es2024",
    "lib": ["es2024", "dom"],
    "strict": true
  },
  "files": ["search.ts"]
}

Output:

true
true
Command Prompt output of tsc -p with lib es2024 compiling without errors and node printing true for string and array includes
tsc finishes with no errors and node prints true for both the string check and the array check.

Remove lib entirely if you don’t need anything special; the target’s default is usually right. Settings like this are why I keep a template, as in creating an empty string array in TypeScript.

TypeScript 7 no longer accepts –target es5

Older answers say “set target to es5 and add lib es2015”. In TypeScript 7 that target is gone, and the compiler stops before type checking:

const city: string = "San Antonio";
const states: string[] = ["TX", "CA", "NY"];

console.log(city.includes("Antonio"));
console.log(states.includes("TX"));

Output:

error TS5108: Option 'target=ES5' has been removed. Please remove it from your configuration.

If you must support very old browsers, compile to ES2015 and transpile further with a bundler. Other compiler errors are covered in checking if an object is undefined in TypeScript.

Use indexOf() when you can’t change lib

If the config isn’t yours to change, indexOf() exists in ES5 and gives the same answer, with one exception:

const city: string = "San Antonio";
const states: string[] = ["TX", "CA", "NY"];

console.log(city.indexOf("Antonio") !== -1);       // same answer as includes()
console.log(states.indexOf("TX") !== -1);
console.log([NaN].indexOf(NaN) !== -1, [NaN].includes(NaN));   // the one difference

Output:

true
true
false true

indexOf can’t find NaN, while includes can. For strings and normal values, the two are interchangeable, and indexOf is also the first step in removing an item from an array in TypeScript.

TS2550 fixes compared

SituationFix
lib: ["es5"] in tsconfiglib: ["es2024", "dom"] or remove lib
Array includes with ES2015lib es2016 or later
--target es5 in TypeScript 7Target es2015+ and transpile with a bundler
Can’t edit tsconfigindexOf(x) !== -1

Here are more TypeScript fixes and guides on strings and arrays:

Frequently asked questions

What does error TS2550 mean?

The property exists in a newer JavaScript version than your lib setting includes. The message names the lib you need.

How do I fix ‘includes’ does not exist on type ‘string’?

Set "lib": ["es2015"] or later in tsconfig.json, or remove lib so it follows your target.

Why does array includes need es2016?

Array.prototype.includes was added in ES2016, one year after string includes.

Can I still use –target es5 in TypeScript 7?

No. TypeScript 7 reports TS5108 because the option was removed. Target es2015 or later.

Is indexOf a safe replacement for includes?

Yes, except that indexOf can’t find NaN in arrays.

Where is the lib compiler option documented?