Creating Custom Errors with Data.TaggedError in Effect Typescript

Hi, can anyone help me with making the custom error either on top of Data.TaggedError/Schema.TaggedError or using just class which extends Error. I want to achieve API something like this

class MyCustomErrorWithNoData extends TaggedApplicationError("custom-error-with-no-data") {}
class MyCustomErrorWithSomeData extends TaggedApplicationError("custom-error-with-some-data")<{
  test: string
  more: number
}> {
  static code: string = "THIS TOO CAN BE OVERRIDE"
  static message: string = "message can be override by extended class"
}

const errorWithNoData = new MyCustomErrorWithNoData("this is the api i am trying to achieve", { code: "RANDOM_LESS_THAN_0.5" })
// errorWithNoData.getData() <- undefined

const errorWithSomeData = new MyCustomErrorWithSomeData({
  more: 1234,
  test: "this is the random number in more"
})
// errorWithSomeData.more <- 1234
// errorWithSomeData.test <- 'this is the random number in more'
// errorWithSomeData.getData() <- this should give object of the data { more: 1234, test: 'this is the random number in more' }


https://effect.website/play/#c2a29dc6aca1

this is so far what i achieved till now, i dont know if this is the way to extend Data.TaggedError properly, i have to explicitly type all the types again, if anyone can help me with this then that would be great, Thanks!
Was this page helpful?