PrismaP
Prisma3w ago
5 replies
Max

Backwards Compatibility with Node Buffer

ORM
Is there any easy way to ensure backwards compatibility with Node Buffers with Prisma, specifically in regards to TypeScript compatiblity.

TS is complaining about how Buffer is not assignable to Uint8Array<ArrayBuffer>. This is because Buffer is actually just Buffer<ArrayBufferLike> under the hood. Buffer<T> extends Uint8Array<T>, but TS does not seem to accept ArrayBufferLike as assignable to ArrayBuffer. My Node types do not include SharedArrayBuffer, so I'm rather confused.

/**
 * Allowed ArrayBuffer types for the buffer of an ArrayBufferView and related Typed Arrays.
 */
interface ArrayBufferTypes {
    ArrayBuffer: ArrayBuffer;
}
type ArrayBufferLike = ArrayBufferTypes[keyof ArrayBufferTypes];


I find it highly doubtful that there is an actual compatibility issue as Buffers are literally just UintArrays, but typescript has started complaining really hard. This type issue started after upgrading from version 6 to version 7.

What's the problem here?
Was this page helpful?