Skip to content

Commit 9268bfa

Browse files
fix: replace @ts-ignore with proper type guard for Node.js streams
1 parent a9568ac commit 9268bfa

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/resources/messages.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { FormData, File } from 'formdata-node';
22
import { ReadableStream } from 'node:stream/web';
3-
import { Readable } from 'node:stream';
43
import APIClient, { RequestOptionsParams } from '../apiClient.js';
54
import { Overrides } from '../config.js';
65
import {
@@ -328,13 +327,15 @@ export class Messages extends Resource {
328327
const contentId = attachment.contentId || `file${index}`;
329328
// Handle different types of content (Buffer, ReadableStream, string)
330329
let file;
330+
// Type guard for Node.js streams
331+
const isNodeStream = (value: unknown): value is { pipe: Function } => {
332+
return value !== null && typeof value === 'object' && typeof (value as any).pipe === 'function';
333+
};
334+
331335
if (attachment.content instanceof ReadableStream) {
332336
// For web ReadableStream
333337
file = attachment.content;
334-
} else if (
335-
// @ts-ignore - Check for Node.js Readable stream
336-
typeof attachment.content?.pipe === 'function'
337-
) {
338+
} else if (isNodeStream(attachment.content)) {
338339
// For Node.js streams (which have pipe method)
339340
file = attachment.content;
340341
} else if (

0 commit comments

Comments
 (0)