error TS2339: Property 'endsWith' does not exist on type 'string' error TS2339: Property 'endsWith' does not exist on type 'string' angularjs angularjs

error TS2339: Property 'endsWith' does not exist on type 'string'


While compiling your typescript code, please point the target to ES6.

tsc --target ES6 "filename"


endsWith is an ES6 function so you need to target ES6 in your TypeScript compiler settings or you can add an interface for it:

interface String {        endsWith(searchString: string, endPosition?: number): boolean;};

[Playground]


Here : I used VS code as an IDE
Issue was :

let fName:String = "Yokey";console.log(fName.anchor("url"));

will result in :

PS C:\MYahya\OS_DEV\typescript_lrn\1> tsc main.tsmain.ts(2,19): error TS2339: Property 'anchor' does not exist on type 'String'.

Solution :
I should include the following tsconfig.json file in the project:

{    "compilerOptions": {        "module": "commonjs",        "target": "es6",        "noImplicitAny": true,        "strictNullChecks": true,        "noImplicitReturns": true,        "noImplicitThis": true,        "noUnusedLocals": true,        "noUnusedParameters": true,        "baseUrl": "../types",        "typeRoots": [            "../types"        ],        "types": [],        "forceConsistentCasingInFileNames": true,    }}

Then I used tsc (without file name) so the transpiler would use the tsconfig.json to transcompile all type script files hosted in the directories to js files.