Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Property 'trimLeft' does not exist on type 'string'. Lib: ["dom", "es2018"]

I am getting this Error when running the following code

let foo = '  foo  '
console.log(foo.trimLeft())
//foo.trimStart() works neither

I know most of the solutions in the internet say, that I have to fix my tsconfig.json to include es20whatever.

The funny thing is, I can use es2018 stuff like Promise.prototype.finally and rest spread etc. VSCode also auto completes trimStart() for me which is odd, because the project and the editor should use the same tsconfig.json. But this particular piece of code does not compile.

Here is my tsconfig.json

{
  "compileOnSave": false,
  "compilerOptions": {
    "outDir": "./dist/out-tsc",
    "baseUrl": "./",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "typeRoots": ["node_modules/@types"],
    "lib": ["es2018", "dom"],
    "plugins": [
      {
        "name": "tslint-language-service",
        "configFile": "./tslint.json"
      }
    ],
    "paths": {
      "foo": ["projects/foo/src/public_api.ts"],
      "bar": ["projects/bar/src/public_api.ts"],
      "baz": ["dist/baz"]
    }
  }
}

I am running this in a monorepo angular folder (as you can see above). Perhaps there is an issue with that, I don't know.

like image 619
uloco Avatar asked Jan 30 '19 10:01

uloco


People also ask

What happens if TypeScript compiler fails to locate configuration file?

If the TypeScript compiler fails to locate this configuration file, you would get an error. But you can provide settings enlisted in this file through the equivalent command-line options which we will cover in the next lesson. So what does this file contain and what exactly it controls?

How to fix finally () error in typescript?

The solution to make the type error go away is to assure the TypeScript compiler that at run-time, the finally () method is going to be available (either natively or via a polyfill). Head over to your project's tsconfig.json file and add the value "es2018.promise" to the "lib" array:

How to display files without creating a build in typescript?

For example, you can use this with the listFiles option to display the files without creating a build. By default, the TypeScript compiler emits JavaScript files ( .js ), source-map files ( .map ), and declaration files ( .d.ts) even if it encounters some compilation errors.

Does typescript change the location of module files?

Therefor . and ./src will form a single virtual directory and TypeScript will compile the program just fine. Even for the rootDirs option, the TypeScript compiler does not change the module path in the compiled code or change the location of the module files in the output files.


2 Answers

Include the library "es2019.string". Update your copy of Typescript if there is no such library. It is rather new and did not exist when this question was asked.

like image 106
Mushinako Avatar answered Nov 16 '22 02:11

Mushinako


Update the typescript library to "typescript": "~3.6.2". Include "es2019" in the tsconfig.json lib's array. It will work.

"target": "es2015",
"typeRoots": [
  "node_modules/@types"
],
"lib": [
  "es2018",
  "es2019",
  "dom"
]
like image 20
mshahin364 Avatar answered Nov 16 '22 03:11

mshahin364