Skip to content

I have an error on an exhaustive check I can't explain: has no call signatures #225

Answered by gvergnaud
rolfst asked this question in Q&A
Discussion options

You must be logged in to vote

Make sure _type on your custom error is declared as string literal (you can use as const for example)

import {match} from 'ts-pattern'

class ErrorA extends Error {
  _type = "A" as const
}
class ErrorB extends Error {
  _type = "B" as const
}
class ErrorC extends Error {
  _type = "C" as const
}

const input = new ErrorA as ErrorA | ErrorB | ErrorC

const res = match(input)
  .with({_type: 'A' }, () => {})
  .with({_type: 'B' }, () => {})
  .with({_type: 'C' }, () => {})
  .exhaustive() // ✅ works

Playground

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by rolfst
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants