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
When consuming a message within a typescript project this may cause some issues when accessing header keys which are not available, e.g.: const testHeader = headers?.test.toString().
In this case typescript wouldn't complain but the application will crash when test header is not set.
Since the index signature previously claimed that the value
was always `Buffer | string` it means that Typescript would
build even when accessing a header key that isn't guaranteed to
be there, and thus crash at runtime unless a null-check is in place.
Fixes#924.
Issue
Currently IHeaders are defined to contain strings or Buffers:
kafkajs/types/index.d.ts
Lines 98 to 100 in 4139127
When consuming a message within a typescript project this may cause some issues when accessing header keys which are not available, e.g.:
const testHeader = headers?.test.toString()
.In this case typescript wouldn't complain but the application will crash when test header is not set.
Suggested solution:
IHeader keys should also be typed with undefined:
The text was updated successfully, but these errors were encountered: