Last active
January 9, 2022 14:52
-
-
Save lomeat/8f303c2b67ecd5207dbcf89875a71f3c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type ErrorCodes = '403a' | '400b'; | |
type Error = { | |
code: ErrorCodes; | |
message: string; | |
}; | |
type ErrorWithMeta<T> = Error & { | |
meta: T; | |
}; | |
type ResponseOne<T> = { | |
result: T | T[]; | |
error: Error; | |
}; | |
type ResponseMany<T> = { | |
result: T[]; | |
error: ErrorWithMeta<Partial<T>>[]; | |
}; | |
type User = { | |
uuid: string; | |
role_id: number; | |
}; | |
const exampleResponseOne: ResponseOne<User> = { | |
result: { | |
uuid: 'iquwye8973iu', | |
role_id: 2, | |
}, | |
error: { | |
code: '403a', | |
message: 'Недостаточно прав', | |
}, | |
}; | |
const exampleResponseMany: ResponseMany<User> = { | |
result: [ | |
{ | |
uuid: 'iquwye8973iu', | |
role_id: 2, | |
}, | |
{ | |
uuid: 'kg2j4hg234', | |
role_id: 34, | |
}, | |
], | |
error: [ | |
{ | |
meta: { | |
uuid: 'kg2j4hg234', | |
}, | |
code: '400b', | |
message: 'Пользователь был удален', | |
}, | |
], | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment