![Property 'toString' does not exist on type 'number'.](https://i.stack.imgur.com/zsjdc.png)
Я ненавижу задавать этот вопрос, я думаю, что это очень простая настройка или типизирование, которое отсутствует в этом новом проекте. Тот факт, что он будет запущен (через ts-node
), говорит мне, что это просто VS Code, жалующийся (но почему?) Поиски в Google и SO пока не дали ничего конкретного.
Код Visual Studio
Версия 1.22.2
Совершить 3aeede733d9a3098f7b4bdc1f66b63b0f48c1ef9
Дата 2018-04-12T16: 38: 45,278Z
Shell 1.7.12
Renderer 58.0.3029.110
Узел 7.9.0
Архитектура x64
> node -v
v9.10.0
> npm -v
5.6.0
> tsc -v
Version 2.8.3
> npm ls --depth=0
api-auth-test@1.0.0 C:\...
+-- @types/node@9.6.6
+-- axios@0.18.0
`-- typescript@2.8.3
> npm ls --depth=0 -g
C:\Users\...\AppData\Roaming\npm
+-- generator@1.0.1
+-- generator-gitignore@0.1.2
+-- npx@10.2.0
+-- ts-node@6.0.1
+-- tslint@5.9.1
+-- typescript@2.8.3
`-- yo@2.0.2
Я нашел упоминание здесь о настройке tsdk в настройках, и я гарантировал, что typcript установлен в локальный node_modules
"typescript.tsdk": "node_modules\\typescript\\lib\\",
Редактирование этого, и ошибка на короткое время исчезает, а затем возвращается (как VS обновляет свой кеш, я думаю.)
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": {}
}