Skip to content

Instantly share code, notes, and snippets.

@nkint
Created November 10, 2022 10:39
Show Gist options
  • Save nkint/0dfbb63dcbc0b68550512361c7f3f0e9 to your computer and use it in GitHub Desktop.
Save nkint/0dfbb63dcbc0b68550512361c7f3f0e9 to your computer and use it in GitHub Desktop.
Typescript refine string array
// fail silently
type Age = "6" | "12" | "24" | "54" | "72" | "84"
type AgeOld = Extract<Age, "72" | "84" | "62">
// fail kabum
type Age = "6" | "12" | "24" | "54" | "72" | "84"
type ExtractOrFail<T, U extends T> = U
type AgeOld = ExtractOrFail<Age, "72" | "84" | "62">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment