Add service response types for standardizing returns.
Typescript is currently having difficulty parsing Service class return types. Providing more explicit return types should improve the situation.
This commit is contained in:
parent
14ece0bed0
commit
0990cf5c56
12
src/lib/server/services/service.types.ts
Normal file
12
src/lib/server/services/service.types.ts
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
type ServiceResponseSuccess<T, D> = {
|
||||||
|
status: T;
|
||||||
|
data?: D;
|
||||||
|
};
|
||||||
|
type ServiceResponseFailure<T, E> = {
|
||||||
|
status: T;
|
||||||
|
code?: E;
|
||||||
|
error?: Error | string;
|
||||||
|
};
|
||||||
|
export type ServiceResponse<D, E, S = "ok", F = "failure"> =
|
||||||
|
| ServiceResponseSuccess<S, D>
|
||||||
|
| ServiceResponseFailure<F, E>;
|
||||||
Loading…
Reference in New Issue
Block a user