Avatar ·

编译TypeScript时出现“tsc command not found”错误

大家好!我刚开始学习TypeScript,在尝试编译第一个文件时遇到了问题。我已经安装了Node.js和npm,创建了一个简单的`hello.ts`文件: ```typescript function greet(name: string): string { return `Привет, ${name}!`; } console.log(greet("Мир")); ``` 我尝试通过终端运行命令`tsc hello.ts`进行编译,但收到错误:“tsc command not found”。我检查了Node.js和npm已安装——`node -v`和`npm -v`命令都能正常工作。我尝试通过`npm install -g typescript`全局安装TypeScript,但之后仍然不行。问题可能出在哪里?是否需要额外配置或设置路径?我使用的是Windows 10,如果这很重要的话。感谢各位帮助新手! <<>>

错误原因及解决方法

错误tsc command not found表示系统在环境变量P中找不到可执行文件tsc。