It recursively finds got (or other fetcher) and tries to fetch JSON, generate types from JSON and place them right before got calls.
For example:
// src/index.ts
import got from 'got'
const post = got('https://jsonplaceholder.typicode.com/posts/1', {
// response type MUST be json
responseType: 'json'
})
console.log(post.title)
After running got-types:
// src/__generated__/post.ts
// can be Post Get ...
export interface GetPostType {
userId: number;
id: number;
title: string;
body: string;
}
// src/index.ts
import got from 'got'
import { GetPostType } from './__generated__/post.ts'
const post = got<GetPostType>('https://jsonplaceholder.typicode.com/posts/1', {
// response type MUST be json
responseType: 'json'
})
console.log(post.title)
It recursively finds
got
(or other fetcher) and tries to fetch JSON, generate types from JSON and place them right beforegot
calls.For example:
After running
got-types
: