我正在尝试让socket.io从使用JQuery和typescript的客户端开始,但我无法这样做。我从这里得到了socket.io的Typescript定义。 (昨天更新了。)
https://github.com/borisyankov/DefinitelyTyped/blob/master/socket.io/socket.io.d.ts
以下是代码:
var socket:Socket = io.connect('http://localhost');
这是我在控制台中遇到的错误。
Uncaught ReferenceError: io is not defined Start.ts:48
socketTest Start.ts:48
start Start.ts:11
(anonymous function) config.ts:24
i.execCb require.js:29
X.check require.js:18
(anonymous function) require.js:23
(anonymous function) require.js:8
(anonymous function) require.js:23
y require.js:7
X.emit require.js:23
X.check require.js:19
X.enable require.js:23
X.init require.js:17
D require.js:14
i.completeLoad require.js:28
i.onScriptLoad
- Update-- 我之前提到的.ts文件加载问题现在已经解决了。
答案 0 :(得分:0)
我怀疑你不小心包含了socket.io的TypeScript定义而不是JavaScript库......
<script src="scripts/socket.d.ts"></script>
<script src="scripts/start.ts"></script>
应该是:
<script src="scripts/socket.js"></script>
<script src="scripts/start.js"></script>