TSError: ⨯ Unable to compile TypeScript:xxx.ts:12:1 - error TS2584:

1,393 阅读1分钟

TSError: ⨯ Unable to compile TypeScript:xxx.ts:12:1 - error TS2584: Cannot find name 'console'. Do you need to change your target library? Try changing the 'lib' compiler option to include 'dom'.

意思是:需要更改目标库吗?尝试改变'lib'编译器选项以包含'dom'

typescript 在编译运行的时ts-node xxx.ts运行的时候 报错

如果项目或当前目录没有tsconfig.json 配置文件

//生成tsconfig.json 编译配置文件
tsc -init

将tsconfig.json中的配置项

"target": "es5", 改成 "target": "es6",

最后运行就ok

ts-node xxx.ts

Demo:

const people: zhangsan = {
  name: "张三",
  age: 20,
};
console.log(people);//=>{ name: '张三', age: 20 }