Skip to content

Instantly share code, notes, and snippets.

@zecka
Created October 9, 2025 12:52
Show Gist options
  • Save zecka/3dd1a165c6abd385ad5954a2d7349afe to your computer and use it in GitHub Desktop.
Save zecka/3dd1a165c6abd385ad5954a2d7349afe to your computer and use it in GitHub Desktop.
Css var to css path union type
type CssPath<T extends string> =
T extends `--${infer Rest}` // enlève les "--" du début
? ReplaceDashWithSlash<Rest> // remplace les tirets restants
: never
type ReplaceDashWithSlash<S extends string> =
S extends `${infer Head}-${infer Tail}`
? `${Head}/${ReplaceDashWithSlash<Tail>}`
: S
// Exemple :
type Demo = "--icon-name-demo" | "--icon-name-demo2"
type DemoPath = CssPath<Demo>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment