You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] is() should return TypeScript type predicate for narrowing #35
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".
Activity