没有课堂设计师没有 'new' - typescript 通过 commonjs
我做了一个服务器聊天 colyseus /node game server framework/. 我用 typescript 从 module:commonjs, 因为 colyseus 建造在 commonjs.
我有一堂课
, 扩展
.
在执行期间,我收到此错误:
麻烦B. javascript:
从课堂上 typescript:
在编译后删除问题字符串时,会轻易跳过错误。 但没有创建基本类,这不是一个完整的解决方案。
我忘了这个问题,似乎与之相关 babel transpiler, 虽然我不使用 babel. 我只使用 tsc / tsconfig.json.
我有一堂课
ChatRoom
, 扩展
Colyseus.Room
.
在执行期间,我收到此错误:
Class constructor Room cannot be invoked without 'new'.
麻烦B. javascript:
function ChatRoom// {
return _super !== null && _super.apply/this, arguments/ || this;
}
从课堂上 typescript:
import {Room} from "colyseus";
export class ChatRoom extends Room {
onInit/options/ {
console.log/"BasicRoom created!", options/;
}
onJoin/client/ {
this.broadcast/`${ client.sessionId } joined.`/;
}
onLeave/client/ {
this.broadcast/`${ client.sessionId } left.`/;
}
onMessage/client, data/ {
console.log/"BasicRoom received message from", client.sessionId, ":", data/;
this.broadcast/`/${ client.sessionId }/ ${ data.message }`/;
}
onDispose// {
console.log/"Dispose BasicRoom"/;
}
}
在编译后删除问题字符串时,会轻易跳过错误。 但没有创建基本类,这不是一个完整的解决方案。
我忘了这个问题,似乎与之相关 babel transpiler, 虽然我不使用 babel. 我只使用 tsc / tsconfig.json.
没有找到相关结果
已邀请:
3 个回复
三叔
赞同来自:
如果父类未分发 /本机类或导入类 ES6, 包括那些被移植的人使用 Babel/, 它不起作用,因为 TypeScript 诀窍
调用父构造函数,而类 ES6 应该只被称为
.
必须解决这个问题 Node.js, 安装
https://www.typescriptlang.org ... .html
TypeScript
价值
. 现代版本 Node.js 支持课程 ES6, 没有必要转机。
预设安装在目标节点上。
同样的问题
https://coderoad.ru/51860043/
.
奔跑吧少年
赞同来自:
我找到了一个基于的解决方案
https://coderoad.ru/44625868/
我需要明确地将Colorsseum明确包含在我的巴比伦引导程序中。 下面是我的配置文件中代码的片段。 webpack:
八刀丁二
赞同来自:
https://github.com/TypeStrong/ts-node
, 你有可能
无法装载 ts-node.
首先确保您将下面的参数设置为
:
然后你可以尝试
或者使用
, 指定您的路径
.