SkillAgentSearch skills...

enums

When creating an enum in TypeScript

Install / Use

npx skills add Razor25000/Analyse-web-pro-v2

Installs into whichever agent you are using.

About this skill
📐

Cursor Rules

Cursor IDE rules (v2)

Quality Score

32/100

Supported Platforms

Cursor

description: When creating an enum in TypeScript globs: alwaysApply: false

Do not introduce new enums into the codebase. Retain existing enums.

If you require enum-like behaviour, use an as const object:

const backendToFrontendEnum = {
  xs: "EXTRA_SMALL",
  sm: "SMALL",
  md: "MEDIUM",
} as const;

type LowerCaseEnum = keyof typeof backendToFrontendEnum; // "xs" | "sm" | "md"

type UpperCaseEnum = (typeof backendToFrontendEnum)[LowerCaseEnum]; // "EXTRA_SMALL" | "SMALL" | "MEDIUM"

Remember that numeric enums behave differently to string enums. Numeric enums produce a reverse mapping:

enum Direction {
  Up,
  Down,
  Left,
  Right,
}

const direction = Direction.Up; // 0
const directionName = Direction[0]; // "Up"

This means that the enum Direction above will have eight keys instead of four.

enum Direction {
  Up,
  Down,
  Left,
  Right,
}

Object.keys(Direction).length; // 8

Related Skills

View on GitHub
GitHub Stars0
CategoryDevelopment
UpdatedNaNy ago
Forks0

Security Score

68/100

Audited on Invalid Date

2 medium1 low