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
相关产品推荐
相关产品推荐

