Skip to content

Instantly share code, notes, and snippets.

@lomeat
Last active January 9, 2022 14:52
Show Gist options
  • Save lomeat/8f303c2b67ecd5207dbcf89875a71f3c to your computer and use it in GitHub Desktop.
Save lomeat/8f303c2b67ecd5207dbcf89875a71f3c to your computer and use it in GitHub Desktop.
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