0
我想測試此代碼顯示在我的打字稿項目中的socket.io站點,但打字稿定義似乎沒有在此功能中調用的界面:Socket.io打字稿定義看起來不正確
這裏是我的代碼:
io.sockets.on('connection', function (socket) {
socket.emit('news', { hello: 'world' });
socket.on('my other event', function (data) {
console.log(data);
});
});
這裏的錯誤:
error TS2094: The property 'sockets' does not exist on value of type '{ listen: { (server: http.Server, options: any, fn: Function): SocketManager; (server: http.Server, fn?: Function): SocketManager; (port: Number): SocketManager; }; }'.
這裏的d.ts文件:
https://github.com/borisyankov/DefinitelyTyped/blob/master/socket.io/socket.io.d.ts#L68
它很高興知道..儘管我對Typescript和定義文件是新手 - 所以我正在調整我的方式。但是如果我讓一個沒有錯誤的論壇運行的話 - 我可能會上傳它。 – EternallyCurious
@EternallyCurious這些文件在8小時前剛剛更新(在您的文章後3次)。可能想嘗試獲取最新信息並查看它是否有效,如果不行,請創建一個問題(https://github.com/borisyankov/DefinitelyTyped/issues),並希望有人會爲您更新:) – John