Skip to main content
Aarunya AppsAarunya Apps

GitHub REST API TypeScript Types (Repository)

TypeScript interfaces for the GitHub REST API repository object. Use these types when building GitHub Apps, Actions, or integrations.

GitHub REST API — Sample JSON

{
  "id": 1296269,
  "node_id": "MDEwOlJlcG9zaXRvcnkxMjk2MjY5",
  "name": "Hello-World",
  "full_name": "octocat/Hello-World",
  "private": false,
  "owner": {
    "login": "octocat",
    "id": 1,
    "avatar_url": "https://github.com/images/error/octocat.gif",
    "type": "User",
    "site_admin": false
  },
  "html_url": "https://github.com/octocat/Hello-World",
  "description": "This your first repo!",
  "fork": false,
  "language": "TypeScript",
  "stargazers_count": 80,
  "watchers_count": 80,
  "forks_count": 9,
  "open_issues_count": 0,
  "default_branch": "main",
  "visibility": "public",
  "created_at": "2011-01-26T19:01:12Z",
  "updated_at": "2011-01-26T19:14:43Z",
  "pushed_at": "2011-01-26T19:06:43Z"
}

Generated TypeScript

export interface Owner {
  login: string;
  id: number;
  avatar_url: string;
  type: string;
  site_admin: boolean;
}

export interface GitHubRepository {
  id: number;
  node_id: string;
  name: string;
  full_name: string;
  private: boolean;
  owner: Owner;
  html_url: string;
  description: string;
  fork: boolean;
  language: string;
  stargazers_count: number;
  watchers_count: number;
  forks_count: number;
  open_issues_count: number;
  default_branch: string;
  visibility: string;
  created_at: string;
  updated_at: string;
  pushed_at: string;
}

How to use

Copy the TypeScript above into a types.ts file in your project. Import the root interface and use it to type your API responses: const data: GitHubRepository = await res.json()

Working with a different JSON payload? Paste any JSON and generate TypeScript interfaces instantly.

Convert your own JSON →

FAQ

How do I type the GitHub REST API response in TypeScript?

Copy the generated interfaces and use them as the return type of your fetch call: const repo: GitHubRepository = await fetch('https://api.github.com/repos/owner/name').then(r => r.json()). For production use, consider @octokit/types which covers all GitHub API shapes.

What is the difference between stargazers_count and watchers_count in GitHub API?

Historically they were different (stargazers = stars, watchers = legacy watchers). Since 2012, GitHub made 'watching' a separate concept and watchers_count now equals stargazers_count. Use stargazers_count for the number of stars.

Does the GitHub API require authentication for repository data?

Public repositories can be fetched unauthenticated (rate limit: 60 requests/hour per IP). Private repositories and higher rate limits (5,000/hour) require a personal access token or GitHub App authentication in the Authorization header.

Powered by Aarunya Apps