Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide an union of type StatusCode. #72

Open
VaibhavAcharya opened this issue Jul 29, 2021 · 0 comments
Open

Provide an union of type StatusCode. #72

VaibhavAcharya opened this issue Jul 29, 2021 · 0 comments

Comments

@VaibhavAcharya
Copy link

VaibhavAcharya commented Jul 29, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants