Skip to content
Discussion options

You must be logged in to vote

Got doesn't have built-in OpenAPI type generation, but you can combine it with tools like openapi-typescript to get typed responses:

import got from 'got';
import type { paths } from './generated/api'; // Generated from your OpenAPI spec

type GetUserResponse = paths['/users/{id}']['get']['responses']['200']['content']['application/json'];

const user = await got('https://api.example.com/users/123').json<GetUserResponse>();

// Now `user` is fully typed based on your OpenAPI spec
console.log(user.name);

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by sindresorhus
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #2230 on February 25, 2023 20:02.