Skip to content

Instantly share code, notes, and snippets.

@MikelArnaiz
Created June 8, 2022 07:12
Show Gist options
  • Save MikelArnaiz/f2780225c2c9cb199365b4daf960bfad to your computer and use it in GitHub Desktop.
Save MikelArnaiz/f2780225c2c9cb199365b4daf960bfad to your computer and use it in GitHub Desktop.
ts-pattern v3 bug
type Foo =
| "Nope"
| ["a", "b", "c", "d", 'e', { x: string }]
function fn(foo: Foo) {
return match<Foo, string>(foo)
.with('Nope', () => 'no')
.with(['a', 'b', 'c', 'd', 'e', __], () => 'yes')
.exhaustive()
}
No overload matches this call.
Overload 1 of 4, '(pattern: Pattern<Foo>, handler: (selections: SeveralAnonymousSelectError<"You can only use a single anonymous selection (with `select()`) in your pattern. If you need to select multiple values, give them names with `select(<name>)` instead">, value: Foo) => string): Match<...>', gave the following error.
Type 'GuardPattern<unknown, unknown> & { string: GuardPattern<unknown, string>; number: GuardPattern<unknown, number>; NaN: GuardPattern<unknown, never>; boolean: GuardPattern<...>; nullish: GuardPattern<...>; }' is not assignable to type 'undefined'.
Overload 2 of 4, '(...args: [Pattern<Foo>, ...Pattern<Foo>[], (value: Foo | ({ x: string; } | "a" | "b" | "c" | "d" | "e")[]) => string]): Match<Foo, string, ["Nope", "Nope"] | ... 9 more ... | [...], unknown>', gave the following error.
Type 'GuardPattern<unknown, unknown> & { string: GuardPattern<unknown, string>; number: GuardPattern<unknown, number>; NaN: GuardPattern<unknown, never>; boolean: GuardPattern<...>; nullish: GuardPattern<...>; }' is not assignable to type 'undefined'.
@MikelArnaiz
Copy link
Author

MikelArnaiz commented Jun 8, 2022

type Foo = 
  | "Nope"
  | ["a", "b", "c", "d", { e: 'e' | 'E', x: string }]

function fn(foo: Foo) {
  return match<Foo, string>(foo)
    .with('Nope', () => 'no')
    .with(['a', 'b', 'c', 'd',  { e: 'e', x: __.string }], () => 'yes')
    .with(['a', 'b', 'c', 'd',  { e: 'E' }], () => 'yes')
    .exhaustive()
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment