unjs / unenv

🕊️ Convert javaScript code to be runtime agnostic
MIT License
390 stars 21 forks source link

`Writable["_data"]` can be null or undefined, with an unsafe `toString()` #21

Closed tarantoj-intrepid closed 2 years ago

tarantoj-intrepid commented 2 years ago

In the following snippet, res._data has a type of any, meaning it can be null | undefined, which do not have toString() methods, causing a runtime error. https://github.com/unjs/unenv/blob/fadb926e8827799aa0e5a33e5a5f0250f3003eac/src/runtime/fetch/call.ts#L35

Definition of the _data property is here https://github.com/unjs/unenv/blob/fadb926e8827799aa0e5a33e5a5f0250f3003eac/src/runtime/node/stream/writable.ts#L19

_data should probably be typed better as either _data: unknown or _data: string | number | object | array | undefined | null to be able to catch this error at build