From 4746c3d71e788670898bad81faf8cfb664c29645 Mon Sep 17 00:00:00 2001 From: Josh Kelley Date: Mon, 4 Aug 2025 11:18:52 -0400 Subject: [PATCH] More specific data types - ArrayBuffer instead of ArrayBufferLike By default, TypeScript interfaces like `DataView` and `Uint8Array` are used with the more generic `ArrayBufferLike` type, representing that they can work with either `ArrayBuffer` or `SharedArrayBuffer`. TypeScript 5.9 now uses stricter types for interfaces such as the DOM `fetch` method: a DOM `BufferSource` is now (correctly) marked as requiring `ArrayBuffer`, not `SharedArrayBuffer`. As a result of that change, trying to use a @msgpack/msgpack `encode` result with a `fetch` call will result in a type error. This change updates the types in the `Encoder` class to use `ArrayBuffer` instead of `ArrayBufferLike`, which reflects their implementation and prevents issues with the newer, stricter interfaces. --- src/Encoder.ts | 8 ++++---- src/encode.ts | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Encoder.ts b/src/Encoder.ts index 43fcd8f..b047c1d 100644 --- a/src/Encoder.ts +++ b/src/Encoder.ts @@ -84,8 +84,8 @@ export class Encoder { private readonly forceIntegerToFloat: boolean; private pos: number; - private view: DataView; - private bytes: Uint8Array; + private view: DataView; + private bytes: Uint8Array; private entered = false; @@ -132,7 +132,7 @@ export class Encoder { * * @returns Encodes the object and returns a shared reference the encoder's internal buffer. */ - public encodeSharedRef(object: unknown): Uint8Array { + public encodeSharedRef(object: unknown): Uint8Array { if (this.entered) { const instance = this.clone(); return instance.encodeSharedRef(object); @@ -152,7 +152,7 @@ export class Encoder { /** * @returns Encodes the object and returns a copy of the encoder's internal buffer. */ - public encode(object: unknown): Uint8Array { + public encode(object: unknown): Uint8Array { if (this.entered) { const instance = this.clone(); return instance.encode(object); diff --git a/src/encode.ts b/src/encode.ts index 9a9d07a..194b67a 100644 --- a/src/encode.ts +++ b/src/encode.ts @@ -11,7 +11,7 @@ import type { SplitUndefined } from "./context.ts"; export function encode( value: unknown, options?: EncoderOptions>, -): Uint8Array { +): Uint8Array { const encoder = new Encoder(options); return encoder.encodeSharedRef(value); }