Export of error classes as values prevents use as types
mmmmmrob opened this issue · comments
Rob Styles commented
DB Errors are exported from objection in objection/typings/objection/index.d.ts
.
const DBError: typeof dbErrors.DBError;
const DataError: typeof dbErrors.DataError;
…snip…
const NotNullViolationError: typeof dbErrors.NotNullViolationError;
The errors are classes that could be used as types if exported differently but the export as value prevents use as a type.
import { UniqueViolationError } from 'objection'
export class UserExists extends Error {
// typescript error:
// 'UniqueViolationError' refers to a value, but is being used as a type here. Did you mean 'typeof UniqueViolationError' ts(2749)
error: UniqueViolationError
}
Exporting the classes directly rather than as a variable would allow them to be used as types.
I'd be happy to put up a PR if someone is able to guide me on what's preferred here.
Rob Styles commented
Is the "correct" way to deal with this to import the errors directly from db-errors
instead of from objection?
Rob Styles commented
This is resolved for me by importing the errors direct from db-errors.