第一次接触TypeScript,配置好环境后,npm
发现连编写个最基本的Hello World都报错,代码以下:spa
const hello:string = "Hello World!"
console.log(hello)
报错代码以下:
error TS1008: Unexpected token; 'module, class, interface..................code
再次编写其余简单代码,又一次报错,代码以下:blog
let x: [number, string]; x = [5, "abc"]; console.log(x[0]);
报错代码以下:
Test.ts(1,5): error TS1005: ';' expected.token
彻底不合逻辑的报错看得我一脸懵逼,后来发现问题,是由于TypeScript版本太低!使用命令 tsc -v,查看版本号Version 1.0.3.0,以下图:ip
如今都已经到了3.x版本了,可是安装下来的居然仍是1.0版本。string
发现问题后,果断从新安装TypeScript,可是问题依然没有解决。io
继续往下查发现原来是环境变量中配置的是旧版本的路径:C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0console
把改路径从Path中删除,用npm命令从新安装TypeScript,版本问题终于解决:编译
从新编译ts文件,问题终于解决!