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

Angular项目出现types/ws的Type 'Server'非泛型错误求助

解决Angular 13项目中TypeScript报错 "Type 'Server' is not generic"

问题根源

你的核心问题是Angular 13与TypeScript 5.1.3版本不兼容:Angular 13仅支持TypeScript 4.0.x ~ 4.6.x,强行使用TS 5.x会触发大量类型定义冲突,包括@types/ws的报错。

解决方案

1. 回退TypeScript到兼容版本

安装Angular 13支持的最高稳定TS版本(4.6.4):

npm install typescript@4.6.4 --save-dev

2. 修复@types/ws依赖冲突

即使更新过@types/ws,依赖缓存或版本不匹配仍可能导致问题,执行以下步骤:

  • 卸载现有@types/ws:
    npm uninstall @types/ws --save-dev
    
  • 安装与TS 4.6.x兼容的@types/ws版本(8.5.3):
    npm install @types/ws@8.5.3 --save-dev
    
  • 清理缓存并重装依赖:
    npm cache clean --force
    # Windows用户替换为下面两行
    # rd /s /q node_modules
    # del package-lock.json
    rm -rf node_modules package-lock.json
    npm install
    

3. 验证TS配置

检查项目根目录的tsconfig.json,确保compilerOptions中没有TS 5.x特有的配置,比如moduleResolution: "bundler",Angular 13推荐设置:

"moduleResolution": "node"

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.19 06:25:07