小程序GIT地址:https://github.com/CFETeam/we...
按照文档上的操作安装nodejs,安装依赖包,安装typescript
tsc app.ts
编译后提示有语法错误
game/room.ts(122,31): error TS2339: Property 'find' does not exist on type 'Room[]'.
game/server.ts(31,9): error TS2322: Type 'string' is not assignable to type 'number'.
https://github.com/CFETeam/we...
照理说find应该是内置的方法才对,不明白为什么报这个错误。
本人之前没有学过typescript,有没有大神知道这个原因是什么。
第一个错是因为
find
是在 ES6 以后才加入到Array.prototype
的一个接口,如果是编译错误的话,可能是类型没找到。我看了tsconfig.json
里设置过"target": "es6"
,如果不在 es6 里可以换成esnext
试试。不过在运行的时候要看是否 es6 以上环境,如果不是,需要引入 polyfill。第二个错报在
this.port = process.env.PORT
,估计是process.env.PORT
定义成string
类型或者推荐成string
类型的,改成this.port = parseInt(process.env.PORT)
就可以了。