TS2339: Property 'includes' does not exist on type 'string'

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



TS2339: Property 'includes' does not exist on type 'string'



I have seen this error mentioned in regards to string arrays but not actual strings. I have a TypeScript file with the line


if (!bus.lineInfo.PublishedLineName.includes(input)) {



This gives me an error of


TS2339: Property 'includes' does not exist on type 'string'.



bus is a variable that implements the bus interface:


bus


bus


interface bus
"lineInfo": string // false if this is "FFFFFF", otherwise it's the color
,
"warnings": boolean



lineInfo.PublishedLineName is declared as a string, and String.prototype.includes() is a function according to MDN, so why does the TypeScript compiler complain about the missing property/method?


lineInfo.PublishedLineName


string


String.prototype.includes()





What is includes or what do you think it is?
– rmlan
Aug 12 at 17:34





I believe it is a string method; I've updated my post to reflect that along with a link
– Michael Kolber
Aug 12 at 17:36





What are the "target" and "lib" settings in your tsconfig.json? String.includes is in ES6.
– Matt McCutchen
Aug 12 at 17:49


tsconfig.json


String.includes





@MattMcCutchen "target" is set to es5. I don't have a "lib" option set. Setting "lib" to "es2015" removes the string error but causes a bunch of errors in thea jQuery d.ts file I have from DefinitelyTyped.
– Michael Kolber
Aug 12 at 17:54


es5




1 Answer
1



You should add es2016 or es7 lib complierOptions in tsconfig.json. Default TypeScript doesn't support some es6 polyfill functions


lib



"compilerOptions":
...
"lib": [
"dom",
"es7"
]




Or change build target to es2016 if you no longer want to support ES5 anymore



"compilerOptions":
...
"target" "es2016"






Perfect! Can you please explain what "dom" does/includes support for?
– Michael Kolber
Aug 12 at 18:44





dom support frontend interface (DOM, Event...). Some library is used for both frontend and backend, when compiling it will alert syntax error. If you develop backend, and there is no error when compiling, you can remove it
– hgiasac
Aug 13 at 2:31


dom






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard