Skip to content

Provide an union of type StatusCode. #72

@VaibhavAcharya

Description

@VaibhavAcharya

Right now I have to use the enum StatusCodes to apply type to an property in Typescript like this:

import { StatusCodes } from "http-status-codes";

export type Response = {
  code: StatusCodes;
  error: null | string;
  data: any;
};

The problem with this approach is that enum type is not strict.
You can apply anything to code & it won't throw an error.

response.code = null;
response.code = 99999;
response.code = "big no";

Learn more about this problem :

Providing a union type would be a big help for DX.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions