Skip to content

Instantly share code, notes, and snippets.

@olehcambel
Created March 13, 2019 11:59
Show Gist options
  • Save olehcambel/ce7c55bd34129c610ad25a1829f53cde to your computer and use it in GitHub Desktop.
Save olehcambel/ce7c55bd34129c610ad25a1829f53cde to your computer and use it in GitHub Desktop.
generic + overload
interface OnSuccessResponse<T> {
statusCode: number
message: string
data: T
error: null
}
export function onSuccess<T>(): OnSuccessResponse<T>
export function onSuccess<T>(params: { message?: string, data?: T | null }): OnSuccessResponse<T>
export function onSuccess<T>(params: {message?: string, data?: T | null}={}) {
return {
statusCode: 200,
message: params.message || 'ok',
data: params.data || null,
error: null
}
}
const t = onSuccess({data: 1})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment