Skip to content
Discussion options

You must be logged in to vote

The issue is that TypeScript infers responseType: 'json' as type string instead of the literal type 'json'. The fix is to use as const on just that property:

const options = {
	method: method,
	searchParams: merged,
	timeout: 6000,
	responseType: 'json' as const,
	resolveBodyOnly: true,
	json: null
};

This tells TypeScript to treat 'json' as the specific literal type instead of the broader string type, which is what Got's types expect.

Also, you probably don't need json: null if you're not sending a JSON body - you can just omit it entirly.

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