Enum after Exclude<> in typescript

Viewed 81

I'm trying to have a sub-enum from another enum in typescript, I found this example

const enum Errcode{
    Ok=0,
    Error=1,
    AccessDeny=201,
    PostsNotFound=202,
    TagNotFound=203,
    //...
}

type SuccessErrcode = Errcode.Ok;
type NotFoundError = Errcode.PostsNotFound|Errcode.TagNotFound;
type ErrorErrcode = Exclude<Errcode, Errcode.Ok>;

the thing is that now ErrorErrcode is a type and not an enum anymore, and I can't use it anymore otherwise I get the error message ErrorErrcode only refers to a type, but is being used as a value here

How can I make an Enum from this union type?

0 Answers
Related