Preserve Literals
Preserve Literals
π¨βπΌ We store role permissions in a configuration object. Without
as const,
TypeScript widens the booleans to boolean, which loses useful information.π¨ Open
and:
- Add
as constto therolesobject soroles.admin.canDeleteUsersstays the literal typetrue - Create a
Roletype from the keys ofroles - Remove the
@ts-expect-erroronceadminCanDelete: truetype-checks - Implement
canDeleteUsers(role: Role): booleanusing therolesdata (admin βtrue, editor/viewer βfalse) - Export
roles,adminCanDelete, andcanDeleteUsersby name
Completion criteria
- Named exports:
roles,adminCanDelete,canDeleteUsers canDeleteUsers('admin')istrue;'editor'and'viewer'arefalse- With
as const,adminCanDeletecan be annotated as the literaltrue
π°
as const preserves true and false as literal types, not just boolean.