这个错误通常是由于代码中缺少分号引起的。应该检查代码中是否所有的语句都以分号结尾,特别是在导入外部模块时。例如,在以下代码中,缺少了分号:
import { Tree } from './Tree'
class Forest {
trees: Array
constructor() { this.trees.push(new Tree()) } }
要解决这个问题,只需要在导入模块的语句后添加分号即可:
import { Tree } from './Tree';
class Forest {
trees: Array
constructor() { this.trees.push(new Tree()) } }
这样就能使编译器不再报错了。