prettymuchbryce/http-status-codes

TypeScript: export union of all codes

OliverJAsh opened this issue · 1 comments

In TypeScript it would be useful to have a union type that represents all possible status codes.

This is possible in user land by doing this:

import HttpStatusCodes from 'http-status-codes';

type HttpStatusCodesMap = typeof HttpStatusCodes;
export type HttpStatusCode = Extract<HttpStatusCodesMap[keyof HttpStatusCodesMap], number>;

However it would be nice if the official type definitions provided this out of the box, as I'm fairly sure it's a common requirement. WDYT?

I'm still not able to get this to work.

I want to define a custom type in my d.ts. However, if I define my type as HttpStatusCodes, compiler says it can´t find the name.

If I add it as a number, everything works fine, so for that, I need a type that is the union of all error codes (number). How do I accomplish that?

Thanks!