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

如何从非主文件导入@actions/github中的Context类型?

解决@actions/github中Context类型导入问题

方案1:升级模块并直接从主入口导入

最新版本的@actions/github(v5及以上)已经将Context类型导出到主模块,直接用以下语句导入即可:

import type { Context } from '@actions/github'

如果你的版本较低,执行命令升级:

npm install @actions/github@latest --save

方案2:调整TypeScript配置(适配旧版本)

若无法升级模块,修改tsconfig.json的模块解析规则:

  1. 将moduleResolution设置为node:
{
  "compilerOptions": {
    "moduleResolution": "node"
  }
}
  1. 尝试使用完整内部路径导入:
import type { Context } from '@actions/github/lib/context'

方案3:临时类型提取(应急方案)

如果上述方法都无效,可手动提取类型:

  1. 找到node_modules/@actions/github/lib/context.d.ts中的Context类型定义
  2. 将其复制到项目自定义类型文件(比如src/types/github.d.ts)
  3. 在代码中直接使用该类型

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.14 13:52:17