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

Angular 14安装apollo-angular遇TS2312错误,求解决方案

解决Angular 14中apollo-angular的TS2312类型错误

问题说明

在Angular 14项目中安装apollo-angular后,出现以下TypeScript错误:

Error: node_modules/apollo-angular/types.d.ts:11:54 - error TS2312: An interface can only extend an object type or intersection of object types with statically known members.

错误出在MutationResult接口继承FetchResult的代码行:

export interface MutationResult<TData = any> extends FetchResult {

解决方案

方案1:安装与Angular 14兼容的apollo-angular版本

Angular 14对应TypeScript 4.6.x,新版本apollo-angular依赖的@apollo/client类型定义已更新,与低版本TS不兼容。需锁定兼容版本:

  1. 卸载当前安装的相关包:
npm uninstall apollo-angular @apollo/client graphql
  1. 安装指定兼容版本:
npm install apollo-angular@2.6.0 @apollo/client@3.6.9 graphql@16.6.0

方案2:跳过库类型检查(临时方案)

如果暂时无法调整版本,可修改项目根目录的tsconfig.json,在compilerOptions中添加:

"skipLibCheck": true

此配置会跳过对第三方库的类型检查,直接绕过该错误,但可能隐藏其他潜在类型问题,建议优先使用方案1。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.17 02:20:34