I am a beginner with type script. I am unable to compile the type script file.
我是一个初学打字的人。我无法编译类型脚本文件。
As I hit Ctrl+Shift+B in the VS Code, i get the error "tsc is not recognised"
当我在VS代码中按Ctrl+Shift+B时,会得到错误"tsc不被识别"
I used npm while downloading transcript.
我在下载文本时使用了npm。
C:\Users\sramesh>npm install -g typescript
C:\Users\sramesh\AppData\Roaming\npm\tsserver -> C:\Users\sramesh\AppData\Roaming\npm\node_modules\typescript\bin\tsserver
C:\Users\sramesh\AppData\Roaming\npm\tsc -> C:\Users\sramesh\AppData\Roaming\npm\node_modules\typescript\bin\tsc
C:\Users\sramesh\AppData\Roaming\npm
`-- typescript@2.1.5
Here is my tasks.json file
这是我的任务。json文件
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"command": "C:\\Users\\sramesh\\AppData\\Roaming\\npm\\node_modules\\typescript\\bin\\tsc",
"isShellCommand": true,
"args": [],
"showOutput": "silent",
"problemMatcher": "$tsc"
}
Can anyone help?
谁能帮忙吗?
3 个解决方案
#1
1
Have you tried running tsc --init
in your directory? This will create a tsconfig.json
file in your directory where you can define your configuration. VSCode will also start using this file once it finds it in your root directory.
你试过在你的目录中运行tsc -init吗?这将创建一个tsconfig。可以在目录中定义配置的json文件。VSCode在根目录中找到这个文件后也将开始使用它。
Check out tsconfig.json documentation for more details.
查看tsconfig。有关更多细节的json文档。
#2
2
I had a similar issue and didn't even showed the version of Typescript after typing tsc -v. Even i had to scratch my head for few days and couldn't solve it.
我也遇到过类似的问题,在输入tsc -v之后,我甚至没有显示打字稿的版本。就连我也得挠挠头几天也解决不了。
At last i did 4 things.
最后我做了四件事。
- installed latest version of nodejs which is i.e. 8.1.3
- 安装最新版本的nodejs,即8.1.3
- installed npm which is 5.1.0 ( npm install npm@latest -g)
- 已安装的npm为5.1.0 (npm安装npm@latest -g)
- installed typescript 2.4.1 ( npm install -g typescript)
- 已安装的打字稿2.4.1 (npm安装-g打字稿)
- as suggested by @Uzair Sajid above. (tsc --init)
- 如上面的@Uzair Sajid所言。(tsc - init)
Now, I can see the TS version, and also compile the TS code.
现在,我可以看到TS版本,也可以编译TS代码。
#3
0
I tried using the command line to set the target.
我尝试使用命令行设置目标。
tsc first.ts --target ES5
This created the first.js( compiled type script in javascript format).I manually moved this file to scripts folder.
这创造了第一个。js(用javascript格式编译的类型脚本)。我手动将这个文件移动到scripts文件夹。
Now when i ran the server using lite-server
command. The browser could find the first.js file and ran the typescript code.
现在,当我使用lite-server命令运行服务器时。浏览器可以找到第一个。js文件并运行打字稿代码。
#1
1
Have you tried running tsc --init
in your directory? This will create a tsconfig.json
file in your directory where you can define your configuration. VSCode will also start using this file once it finds it in your root directory.
你试过在你的目录中运行tsc -init吗?这将创建一个tsconfig。可以在目录中定义配置的json文件。VSCode在根目录中找到这个文件后也将开始使用它。
Check out tsconfig.json documentation for more details.
查看tsconfig。有关更多细节的json文档。
#2
2
I had a similar issue and didn't even showed the version of Typescript after typing tsc -v. Even i had to scratch my head for few days and couldn't solve it.
我也遇到过类似的问题,在输入tsc -v之后,我甚至没有显示打字稿的版本。就连我也得挠挠头几天也解决不了。
At last i did 4 things.
最后我做了四件事。
- installed latest version of nodejs which is i.e. 8.1.3
- 安装最新版本的nodejs,即8.1.3
- installed npm which is 5.1.0 ( npm install npm@latest -g)
- 已安装的npm为5.1.0 (npm安装npm@latest -g)
- installed typescript 2.4.1 ( npm install -g typescript)
- 已安装的打字稿2.4.1 (npm安装-g打字稿)
- as suggested by @Uzair Sajid above. (tsc --init)
- 如上面的@Uzair Sajid所言。(tsc - init)
Now, I can see the TS version, and also compile the TS code.
现在,我可以看到TS版本,也可以编译TS代码。
#3
0
I tried using the command line to set the target.
我尝试使用命令行设置目标。
tsc first.ts --target ES5
This created the first.js( compiled type script in javascript format).I manually moved this file to scripts folder.
这创造了第一个。js(用javascript格式编译的类型脚本)。我手动将这个文件移动到scripts文件夹。
Now when i ran the server using lite-server
command. The browser could find the first.js file and ran the typescript code.
现在,当我使用lite-server命令运行服务器时。浏览器可以找到第一个。js文件并运行打字稿代码。