You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Angular从9升级到15后@types/ws报错:类型'Server'不是泛型

Angular ng serve 报错:Type 'Server' is not generic

报错详情

Error: node_modules/@types/ws/index.d.ts:328:18 - error TS2315: Type 'Server' is not generic.

328         server?: HTTPServer<V> | HTTPSServer<V> | undefined;
                     ~~~~~~~~~~~~~


Error: node_modules/@types/ws/index.d.ts:328:34 - error TS2315: Type 'Server' is not generic.

328         server?: HTTPServer<V> | HTTPSServer<V> | undefined;
                                     ~~~~~~~~~~~~~~

已安装@types/node:12.20.55和@types/ws:8.5.4,但错误仍存在。

问题原因

@types/ws@8.5.4依赖的@types/node版本要求高于12.x,Node.js 12对应的@types/node中,Server类型并非泛型定义,而高版本@types/node(14+)里Server才是泛型,两者类型定义不兼容导致报错。

解决方案

  • 方案一:升级@types/node到兼容版本
    执行命令安装适配的高版本@types/node(需和你本地Node.js实际版本匹配,比如14/16/18):

    npm install @types/node@14 --save-dev
    
  • 方案二:降级@types/ws到适配@types/node@12的版本
    如果无法升级Node.js或@types/node,可降级@types/ws到7.x版本,该版本适配@types/node@12的类型定义:

    npm install @types/ws@7 --save-dev
    

内容的提问来源于stack exchange,提问作者Akash Kumawat

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.17 03:31:58