Last active
January 8, 2024 19:23
-
-
Save serifcolakel/825423caa9e37a515ad22b355cc55414 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @description This is a test for the `InferValueFromColor` type. | |
* @example | |
* type Color = '#fff'; | |
* type Value = InferValueFromColor<Color>; // Value is 'fff' | |
* @example | |
* type Color = '#fff' | '#000'; | |
* type Value = InferValueFromColor<Color>; // Value is 'fff' | '000' | |
* @example | |
* type Color = '#fff' | '#000' | '#aaa'; | |
* type Value = InferValueFromColor<Color>; // Value is 'fff' | '000' | 'aaa' | |
*/ | |
type InferValueFromColor<Color extends string> = Color extends `#${infer Value}` ? `#${Value}` : never; | |
/** | |
* @description This is a test for tailwind color the `InferValueFromTWColor` type. | |
* @example | |
* type Color = 'bg-white'; | |
* type Value = InferValueFromTWColor<Color>; // Value is never | |
* @example | |
* type Color = 'bg-white-100'; | |
* type Value = InferValueFromTWColor<Color>; // Value is { nameSpace: 'bg', color: 'white', tone: '100' } | |
*/ | |
type InferValueFromTWColor<Color extends string> = Color extends `${infer N}-${infer C}-${infer T}` ? { | |
nameSpace: N; | |
color: C; | |
tone: T; | |
} : never; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment