Skip to content

Instantly share code, notes, and snippets.

Created May 15, 2022 23:00
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Generic interfaces in TypeScript
interface HttpResponse<T> {
code: number;
data: T;
interface ResponseData {
completed: boolean;
id: number;
title: string;
userId: number;
async function getJson<T>(url: string): Promise<HttpResponse<T>> {
const response = await fetch(url);
const data: T = await response.json();
return {
code: response.status,
(async () => {
const response = await getJson<ResponseData>('');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment