Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error TS2339: Property 'startsWith' does not exist on type 'string' #12383

Closed
rajinder-yadav opened this issue Nov 19, 2016 · 6 comments
Closed
Labels
Question An issue which isn't directly actionable in code

Comments

@rajinder-yadav
Copy link

rajinder-yadav commented Nov 19, 2016

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:

@j-oliveras
Copy link
Contributor

j-oliveras commented Nov 19, 2016

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".

Compiler options.

@rajinder-yadav
Copy link
Author

Thanks, closing!

@RyanCavanaugh RyanCavanaugh added the Question An issue which isn't directly actionable in code label Nov 21, 2016
@marcus-petty
Copy link

marcus-petty commented Feb 21, 2018

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) ||`

@mhegazy
Copy link
Contributor

mhegazy commented Feb 21, 2018

"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

@marcus-petty
Copy link

thx

@0x80
Copy link

0x80 commented May 14, 2018

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/**/*"]
}

@microsoft microsoft locked and limited conversation to collaborators Jul 31, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

6 participants