34
loading...
This website collects cookies to deliver better user experience
export enum EHttpStatusCode {
Ok = 200,
BadRequest = 400,
Unauthorized = 401,
Forbidden = 403,
NotFound = 404,
ServerError = 500,
}
export var EHttpStatusCode;
(function (EHttpStatusCode) {
EHttpStatusCode[EHttpStatusCode["Ok"] = 200] = "Ok";
EHttpStatusCode[EHttpStatusCode["BadRequest"] = 400] = "BadRequest";
EHttpStatusCode[EHttpStatusCode["Unauthorized"] = 401] = "Unauthorized";
EHttpStatusCode[EHttpStatusCode["Forbidden"] = 403] = "Forbidden";
EHttpStatusCode[EHttpStatusCode["NotFound"] = 404] = "NotFound";
EHttpStatusCode[EHttpStatusCode["ServerError"] = 500] = "ServerError";
})(EHttpStatusCode || (EHttpStatusCode = {}));
as const
after the declaration
export const httpStatusCode = {
Ok: 200,
BadRequest: 400,
Unauthorized: 401,
Forbidden: 403,
NotFound: 404,
ServerError: 500,
} as const;
as const
statement for sure.class HttpResponse {
code: HttpStatusCode = 200;
// other stuff here
}
type HttpStatusCodeKey = keyof typeof httpStatusCode;
export type HttpStatusCode = typeof httpStatusCode[HttpStatusCodeKey];
httpStatusCode
object's values. And the good news is that this type is only used for building TS and is then removed from the transpiled output. So the only thing JS will have is the object.class HttpResponse {
code: HttpStatusCode = httpStatusCode.Ok;
// other stuff here
}
httpStatusCode
) because it's a value. On the other hand, the type extracted from the object is PascalCased (HttpStatusCode
). So it follows usual convention and is then easy to differentiate type from value object.