I'm using Octokit which is a GitHub client. I'm trying to read the contents of a directory and the return type of octokit.repos.getContent
is a type union that has many possible values.
I'm trying to narrow the return value of getContent
to only one of those options, it looks like this:
"content-directory": {
type: 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: {
git: string | null;
html: string | null;
self: string;
};
}[]
I created a type
out of it:
type DirectoryItems = components["schemas"]["content-directory"];
and now I'm trying to use it in a type guard:
const { data } = await octokit.repos.getContent({
// ...
});
if(data instanceof DirectoryItems) {
}
but it says
'DirectoryItems' only refers to a type, but is being used as a value here.
How can I narrow the type of data
to make sure that it is indeed an array of "content-directory" items?