没有课堂设计师没有 'new' - typescript 通过 commonjs

我做了一个服务器聊天 colyseus /node game server framework/. 我用 typescript 从 module:commonjs, 因为 colyseus 建造在 commonjs.

我有一堂课
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.
已邀请:

三叔

赞同来自:

TypeScript 在其模拟中转移课程 ES5, 但是,通过这种方式,整个类别等级就必须移动到 ES5.

如果父类未分发 /本机类或导入类 ES6, 包括那些被移植的人使用 Babel/, 它不起作用,因为 TypeScript 诀窍
var instance = Parent.call/this, .../ || this

调用父构造函数,而类 ES6 应该只被称为
new

.

必须解决这个问题 Node.js, 安装
https://www.typescriptlang.org ... .html
TypeScript
target

价值
es6

. 现代版本 Node.js 支持课程 ES6, 没有必要转机。
预设安装在目标节点上。

同样的问题
https://coderoad.ru/51860043/
.

奔跑吧少年

赞同来自:

我使用了同样的问题 javascript, webpack 和 babel /但不是 TypeScript/.

我找到了一个基于的解决方案
https://coderoad.ru/44625868/
我需要明确地将Colorsseum明确包含在我的巴比伦引导程序中。 下面是我的配置文件中代码的片段。 webpack:


module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
include: /colyseus/,
use: {
loader: "babel-loader"
}
}
]
},

八刀丁二

赞同来自:

对于那些 , 谁用途
https://github.com/TypeStrong/ts-node
, 你有可能
tsconfig.json

无法装载 ts-node.

首先确保您将下面的参数设置为
tsconfig.json

:


{
"compilerOptions": {
"target": "ES6",
...
}
}


然后你可以尝试
ts-node --script-mode

或者使用
--project

, 指定您的路径
tsconfig.json

.

要回复问题请先登录注册