如何扩展nodejs模块的打字稿定义

我使用nodejs模块“ws”,并安装types我dt〜ws

 import * as WebSocket from "ws"; function add(client:WebScoket){ let cid = client.clientId; } 

我想扩展 WebSocket属性clientId ,但我不知道如何。

我已经尝试在我的定义文件index.d.ts编写跟随代码

 declare module "ws" { class WebSocket { ip: string; clientId: number; project: string; } } 

但效果不好

你有没有尝试过使用websocket类的扩展和使用它?

例如:

 interface WebSocketWithCliendId extends WebSocket { clientId: string; }