Octokit repos.getContent method from @actions/github content field typescript error
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 5.9k
- Forks
- 1.8k
- PR merge metrics
- No merged PRs in 30d
Description
Describe the bug
I receive the following typescript error when i try to access data.content from a response of getContent().
Property 'content' does not exist on type '{ type: string; encoding: string; size: number; name: string; path: string; content: string; sha: string; url: string; git_url: string | null; html_url: string | null; download_url: string | null; _links: { ...; }; target?: string | undefined; submodule_git_url?: string | undefined; } | { ...; } | { ...; }'.
Property 'content' does not exist on type '{ type: string; target: string; size: number; name: string; path: string; sha: string; url: string; git_url: string | null; html_url: string | null; download_url: string | null; _links: { git: string | null; html: string | null; self: string; }; }'
I found a similar issue here. Which if i do switch imports to use import { Octokit } from '@octokit/rest';, the types will work. However this is not what I will want to use in a github action.
https://github.com/octokit/rest.js/issues/32
To Reproduce
Here's a code snippet with the above typescript error:
import * as github from '@actions/github';
const octokit = github.getOctokit('token');
async function foo() {
const { data } = await octokit.rest.repos.getContent();
if (!Array.isArray(data)) {
if (data.type === 'file') {
data.content;
}
}
}
foo();
Expected behavior
Given we check the type for the file, i would expect it to resolve as the other github issue noted.
Screenshots
Desktop (please complete the following information):
- OS: MacOS 13.3.1
Package versions
- @actions/github 5.1.1
- @octokit/core 3.6.0 (version 3 required by actions/github
- @octokit/core 4.1.0 (version 4 is required by @octokit/rest 19)
- @octokit/rest 19.0.7
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the TypeScript error from the provided @actions/github getOctokit().rest.repos.getContent() snippet, then inspect the response declarations exposed by that client and compare them with the @octokit/rest behavior described in the linked issue. Done means narrowing data by type === 'file' exposes content without an error and the relevant type behavior is covered by a regression check.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- github, typescript
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100