Bug Description
is(err, SomeError) returns a plain boolean, not a TypeScript type predicate. Consumers cannot narrow the error type after the check:
if(is(err,NotFoundError)){// err is still typed as ErrorInstance<unknown> — no narrowingconsole.log(err.fields.slug)// TS error}This forces consumers to cast (err as NotFoundError) or duplicate the narrowing logic. With three try/catch blocks per command and ~7 error types, this churn adds up.
Steps to Reproduce
npm install @deessejs/errors- Create
repro.ts:
import{error,is}from"@deessejs/errors"constNotFoundError=error({name: "NotFoundError"})constOtherError=error({name: "OtherError"})consterr: unknown=NotFoundError()if(is(err,NotFoundError)){// Expected: err is now inferred as NotFoundError instance// Actual: err is still unknownconsole.log(err)}- Run
tsc --noEmit and try to access any field on err inside the if branch.
Expected Behavior
is() should return err is ErrorInstance<TError, ...> (a type predicate), so TypeScript narrows automatically.
Actual Behavior
No narrowing. The if branch treats err as unknown unless the consumer casts.
Environment
- Node.js: 22.x
- pnpm: 11.0.0
- OS: Linux
- @deessejs/errors: 1.1.1
Consumer
deessejs/deessejs monorepo, apps/cli workspace. Would unblock the planned migration of commands/info.ts, commands/list.ts, commands/init.ts to use is(err, CliError) instead of err.name === "CliError".
Bug Description
is(err, SomeError)returns a plainboolean, not a TypeScript type predicate. Consumers cannot narrow the error type after the check:This forces consumers to cast (
err as NotFoundError) or duplicate the narrowing logic. With threetry/catchblocks per command and ~7 error types, this churn adds up.Steps to Reproduce
npm install @deessejs/errorsrepro.ts:tsc --noEmitand try to access any field onerrinside theifbranch.Expected Behavior
is()should returnerr is ErrorInstance<TError, ...>(a type predicate), so TypeScript narrows automatically.Actual Behavior
No narrowing. The
ifbranch treatserrasunknownunless the consumer casts.Environment
Consumer
deessejs/deessejsmonorepo,apps/cliworkspace. Would unblock the planned migration ofcommands/info.ts,commands/list.ts,commands/init.tsto useis(err, CliError)instead oferr.name === "CliError".