cf.completefrontend

Write the codeEasy

Write TupleToUnion<T>, and use it to derive a Role union from a roles array.

roles and sizes are the options two dropdowns show. Role should be the union of the roles, "admin" | "editor" | "viewer", and Size the union of the sizes' values, "sm" | "lg", both worked out from the arrays so a list and its type can't drift apart. Write TupleToUnion<T>, change the arrays so their literal values are kept, and derive both types.

Write this
type TupleToUnion<T extends readonly unknown[]> = never; const roles = ["admin", "editor", "viewer"];type Role = TupleToUnion<typeof roles>; const sizes = [  { value: "sm", label: "Small" },  { value: "lg", label: "Large" },];type Size = never;

Solve it in the editor

The answer

Write it yourself first. Then compare it with a reference solution and the checks it passes.

Checking your sign-in…