tsc 2.0.10
Code
let tok = ":name";
if(tok.startsWith(":")) <--- false error: error TS2339: Property 'startsWith' does not exist on type 'string'
// A *self-contained* demonstration of the problem follows...
Expected behavior:
should know this is a method on a JS string.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith
Actual behavior:
The method endsWith is declared into es6 (es2015). Make sure your target is es6 or higher (if target is not defined defaults to es3) or use lib option to include "es2015.core".
Thanks, closing!
We have this but still get the same error
{
"compilerOptions": {
"target": "es2015",
"module": "commonjs",
"sourceMap": true
},
"include": [
],
"exclude": [],
"lib":[
"es2015"
]
}
error TS2339: Property 'startsWith' does not exist on type 'string'.
the code:
`if (attrKey.startsWith(IDENTIFIER) ||`
"lib" should be part of "compilerOptions" and not a sibling . see http://www.typescriptlang.org/docs/handbook/compiler-options.html and http://json.schemastore.org/tsconfig
thx
I just ran into this problem in one of my Firebase cloud functions. I can't see anything wrong with my config, you?
{
"compilerOptions": {
"target": "es2015",
"module": "commonjs",
"lib": ["es2015", "es2016", "esnext"],
"sourceMap": true,
"outDir": "build",
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"noImplicitThis": true,
"alwaysStrict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"moduleResolution": "node",
"plugins": [
{
"name": "tslint-language-service"
}
]
},
"include": ["src/**/*"]
}
Most helpful comment
I just ran into this problem in one of my Firebase cloud functions. I can't see anything wrong with my config, you?