Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
interface GreatClientConfig {
url: string
}
interface GreatClientResponse {
data: {
datetime: string
isGreat: boolean
}
}
const myGreatClientFactory = (config: GreatClientConfig) => {
return {
getConfig: (): GreatClientConfig => config,
doSomethingAsync: async (path: string): Promise<GreatClientResponse> => {
const response = await fetch(`${config.url}/${path}`)
if (!response.ok) {
throw new Error(`Something failed: ${response.status}`)
}
return await response.json()
}
}
}
const myGreatClient = myGreatClientFactory({ url: 'https://it.is-great.com/api' })
type doSomethingAsyncParams = Parameters<typeof myGreatClient.doSomethingAsync>
type doSomethingasyncReturnType = ReturnType<typeof myGreatClient.doSomethingAsync>
@swashcap

This comment has been minimized.

Copy link
Owner Author

@swashcap swashcap commented Sep 24, 2019

Why you default to 4 spaces, VS Code 🤦‍♂️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.