File tree Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -289,6 +289,19 @@ Key benefits:
289289 - Helps catch type mismatches at compile time while preserving narrowed inferred types.
290290
291291``` ts
292+ // Array constant
293+ type UserRole = ' admin' | ' editor' | ' moderator' | ' viewer' | ' guest' ;
294+
295+ // ❌ Avoid constant of wide type
296+ const DASHBOARD_ACCESS_ROLES: ReadonlyArray <UserRole > = [' admin' , ' editor' , ' moderator' ];
297+
298+ // ❌ Avoid constant with incorrect values
299+ const DASHBOARD_ACCESS_ROLES = [' admin' , ' contributor' , ' analyst' ] as const ;
300+
301+ // ✅ Use immutable constant of narrowed type
302+ const DASHBOARD_ACCESS_ROLES = [' admin' , ' editor' , ' moderator' ] as const satisfies ReadonlyArray <UserRole >;
303+
304+ // Object constant
292305type OrderStatus = {
293306 pending: ' pending' | ' idle' ;
294307 fulfilled: boolean ;
You can’t perform that action at this time.
0 commit comments