Theo's Typesafe CultTTC
Theo's Typesafe Cult3y ago
3 replies
MagerX

Opinion on DX of this code, is it too confusing or easy to grasp?

const roles = makeEnum("User", "Admin", "Owner"); // Type: "User", "Admin", "Owner"
export type Roles = ExtractEnumType<typeof roles>; // "User" | "Admin" | "Owner"
export const Roles = TrimEnum(roles);


const [IRoles, iroles] = makeEnum("User", "Admin", "Owner"); // Type: "User", "Admin", "Owner"
export type IRoles = ExtractEnumType<typeof iroles>; // "User" | "Admin" | "Owner"
export{ IRoles };

Just wanted to get some second opinions on a fun library I'm working on. I'm reaching a point where typescript limitations are making me have to do strange patterns to get my desired behavior, so I want to try to pick a variation of it that resonates with other people and not just myself.

As of the moment these are the only 2 that I could imagine, but if anyone has an idea on another way that I could return a type value/object and export them so that they appear as the same type.

Additionally, is it safe to say that the top version is the more 'normal' version and the bottom one is definitely more react-like because of the array destrucuring or is that something common in all of javascript?
Was this page helpful?