arktypea
arktype10mo ago
TheGuy

Is there a good way to use an array of fields mapped from an object into array as string literals?

So probably really simple and I am just missing something.

I am trying to achieve the following:

export const SCOPES = {
  user: {
    can_edit: "can_edit",
  },
  organiser: {
    can_edit: "can_edit",
  },
  event: {
    can_edit: "can_edit",
  }
} as const;

const test = Object.values(SCOPES.user).map((scope) => `'${scope}'`);

export const user = type({
  "...": permissionBase,
  type: "'user'",
  scopes: test
});


Not sure if this is possible but I may be missing something? The issue obviously comes in that its not a as const. But trying to figure out how I can achieve something like that. In this case its supposed to be an array of those strings.
Was this page helpful?