fix: 수정된 타입 정의 및 불필요한 캐스팅 제거

This commit is contained in:
2025-12-27 05:11:46 +00:00
parent 8b95824cb6
commit 297baea126
2 changed files with 4 additions and 5 deletions
+1 -1
View File
@@ -1,2 +1,2 @@
export type Bytes = ArrayBuffer | DataView | Uint8Array<ArrayBuffer>;
export type Bytes = ArrayBuffer | DataView<ArrayBuffer> | Uint8Array<ArrayBuffer>;
export type BytesLike = Bytes | string;
@@ -18,14 +18,13 @@ export function convertBytesLikeToUint8Array(
return new Uint8Array(data);
}
if (data instanceof DataView) {
const view = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
return new Uint8Array(view) as Uint8Array<ArrayBuffer>;
return new Uint8Array<ArrayBuffer>(data.buffer, data.byteOffset, data.byteLength);
}
if (typeof (data) === 'string') {
if (encodeUTF8) {
return (new TextEncoder()).encode(data) as Uint8Array<ArrayBuffer>;
return (new TextEncoder()).encode(data);
}
return new Uint8Array(data.split('').map((s) => s.codePointAt(0) as number)) as Uint8Array<ArrayBuffer>;
return new Uint8Array(data.split('').map((s) => s.codePointAt(0) as number));
}
throw new Error('Unsupported BytesLike');
}