Skip to content

[Typescript] Improve types for isKafkaJSError - #498

Open
Leo Singer (lpsinger) wants to merge 1 commit into
confluentinc:masterfrom
lpsinger:isKafkaJSError-type-predicate
Open

[Typescript] Improve types for isKafkaJSError#498
Leo Singer (lpsinger) wants to merge 1 commit into
confluentinc:masterfrom
lpsinger:isKafkaJSError-type-predicate

Conversation

@lpsinger

Copy link
Copy Markdown

Change the input parameter's type from Error to any. Now you no longer have to write this to silence all type errors:

try {
  // ...
} catch (e) {
  if (e instanceof Error && isKafkaJSError(e) {
    // ...
  }
}

Now you can simply write:

try {
  // ...
} catch (e) {
  if (isKafkaJSError(e)) {
    // ...
  }
}

Declare it as a type predicate so that TypeScript understands that if the function returns true that it narrows the type to KafkaJSError.

Please prefix all TypeScript pull-requests with [Typescript]

What

Checklist

  • Contains customer facing changes? Including API/behavior changes
  • Did you add sufficient unit test and/or integration test coverage for this PR?
    • If not, please explain why it is not required

References

JIRA:

Test & Review

Open questions / Follow-ups

@lpsinger
Leo Singer (lpsinger) requested review from a team as code owners June 23, 2026 12:21
@lpsinger
Leo Singer (lpsinger) force-pushed the isKafkaJSError-type-predicate branch from 4a28b57 to 9605d94 Compare June 23, 2026 12:22
@lpsinger Leo Singer (lpsinger) changed the title Improve types for isKafkaJSError [Typescript] Improve types for isKafkaJSError Jun 23, 2026
Change the input parameter's type from `Error` to `any`. Now you
no longer have to write this to silence all type errors:

```typescript
try {
  // ...
} catch (e) {
  if (e instanceof Error && isKafkaJSError(e) {
    // ...
  }
}
```

Now you can simply write:

```typescript
try {
  // ...
} catch (e) {
  if (isKafkaJSError(e)) {
    // ...
  }
}
```

Declare it as a type predicate so that TypeScript understands that
if the function returns `true` that it narrows the type to
`KafkaJSError`.
@lpsinger
Leo Singer (lpsinger) force-pushed the isKafkaJSError-type-predicate branch from 9605d94 to d28ab2a Compare July 20, 2026 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant