Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS Code Property 'toString' does not exist on type 'number'

Property 'toString' does not exist on type 'number'.

I hate asking this question, I imagine it is a very simple setting or typings thing that this fresh project is missing. The fact that it will run (via ts-node) tells me it is just VS Code complaining (but, why?) Google and SO searches turned up nothing concrete yet.

Visual Studio Code
Version 1.22.2
Commit 3aeede733d9a3098f7b4bdc1f66b63b0f48c1ef9
Date 2018-04-12T16:38:45.278Z
Shell 1.7.12
Renderer 58.0.3029.110
Node 7.9.0
Architecture x64


> node -v
v9.10.0


> npm -v
5.6.0


> tsc -v
Version 2.8.3


> npm ls --depth=0
[email protected] C:\...
+-- @types/[email protected]
+-- [email protected]
`-- [email protected]


> npm ls --depth=0 -g
C:\Users\...\AppData\Roaming\npm
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
`-- [email protected]

I found mention here of the tsdk setting in preferences, settings, and I ensured that typescript is installed into the local node_modules

"typescript.tsdk": "node_modules\\typescript\\lib\\",

Editing this, and the error disappears briefly, then returns (as VS refreshing its cache I imagine.)

tsconfig.json

{
  "compilerOptions": {
    "target": "esnext",                       /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */
    "module": "commonjs",                     /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
    "lib": [ ],                               /* Specify library files to be included in the compilation. */
    "sourceMap": true,                        /* Generates corresponding '.map' file. */
    "strict": true,                           /* Enable all strict type-checking options. */
    "esModuleInterop": true                   /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
  }
}

package.json

{
  "name": "api-auth-test",
  "version": "1.0.0",
  "description": "",
  "main": "app.ts",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@types/node": "^9.6.6",
    "axios": "~0.18.0",
    "typescript": "^2.8.3"
  },
  "devDependencies": {}
}
like image 700
t.j. Avatar asked Dec 09 '25 17:12

t.j.


1 Answers

Your tsconfig lib is missing the es2015 entry or rather is empty.

"lib": [
    "dom",
    "es2015"
],

Removing es2015 gave me the error you are facing. For information on --lib option see What does the tsconfig option "lib" do?

like image 89
Suraj Rao Avatar answered Dec 11 '25 06:12

Suraj Rao



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!