Skip to content

Commit

Permalink
Add ExhaustedTypeError
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaw3d committed Jun 7, 2023
1 parent 4aaf647 commit b702bc7
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/types/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,19 @@ export interface ErrorPayload {
code: AppErrors
message: string
}

// Adds strict type-check that a type was exhausted
// https://www.typescriptlang.org/docs/handbook/2/narrowing.html#exhaustiveness-checking
// https://stackoverflow.com/questions/41102060/typescript-extending-error-class
export class ExhaustedTypeError extends Error {
constructor(
messagePrefix: string,
exhaustedType: 'Expected type to be exhausted, but this type was not handled',
) {
super(
`${messagePrefix}: Expected type to be exhausted, but this type was not handled: ${JSON.stringify(
exhaustedType,
)}`,
)
}
}

0 comments on commit b702bc7

Please sign in to comment.