Skip to content

Commit

Permalink
feat: TypeScript 5.7 support
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret committed Jan 29, 2025
1 parent f30741c commit f5c6ee9
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"deno.enable": true,
"deno.unstable": true,
"deno.path": "V:\\deno\\target\\debug\\deno.exe",
"editor.formatOnSave": true,
"editor.defaultFormatter": "denoland.vscode-deno"
}
8 changes: 8 additions & 0 deletions bytes/_uint8Array.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
type IsAny<T> = 0 extends (1 & T) ? true : false;
// @ts-ignore Uint8array is not generic in TS < 5.7
type NewUint8Array<T> = Uint8Array<T>;

type IsOld = IsAny<NewUint8Array<ArrayBuffer>>;
type Uint8Array2<T = ArrayBufferLike> = IsOld extends true ? Uint8Array
: NewUint8Array<T>;
export type { Uint8Array2 as Uint8Array };
6 changes: 5 additions & 1 deletion bytes/concat.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright 2018-2025 the Deno authors. MIT license.
// This module is browser compatible.

import type { Uint8Array } from "./_uint8Array.ts";

/**
* Concatenate an array of byte slices into a single slice.
*
Expand All @@ -18,7 +20,9 @@
* assertEquals(concat([a, b]), new Uint8Array([0, 1, 2, 3, 4, 5]));
* ```
*/
export function concat(buffers: Uint8Array[]): Uint8Array {
export function concat(
buffers: Uint8Array<ArrayBufferLike>[],
): Uint8Array<ArrayBuffer> {
let length = 0;
for (const buffer of buffers) {
length += buffer.length;
Expand Down
2 changes: 1 addition & 1 deletion cli/_tools/compare_with_rust.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Deno.test("fast-check equality with unicode_width Rust crate", async (t) => {
// JSON stringify to allow "\0" chars to cross FFI boundary in a null-terminated string
// deno-lint-ignore no-explicit-any
(str: any) =>
unicodeWidth(str) ===
BigInt(unicodeWidth(str)) ===
dylib.symbols.unicode_width(toCString(JSON.stringify(str))),
),
);
Expand Down
8 changes: 8 additions & 0 deletions crypto/_uint8array.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
type IsAny<T> = 0 extends (1 & T) ? true : false;
// @ts-ignore Uint8array is not generic in TS < 5.7
type NewUint8Array<T> = Uint8Array<T>;

type IsOld = IsAny<NewUint8Array<ArrayBuffer>>;
type Uint8Array2<T = ArrayBufferLike> = IsOld extends true ? Uint8Array
: NewUint8Array<T>;
export type { Uint8Array2 as Uint8Array };
6 changes: 4 additions & 2 deletions crypto/_wasm/lib/deno_std_wasm_crypto.generated.d.mts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// deno-lint-ignore-file
// deno-fmt-ignore-file

import { Uint8Array } from "../../_uint8array.ts"

export interface InstantiateResult {
instance: WebAssembly.Instance;
exports: {
Expand Down Expand Up @@ -37,7 +39,7 @@ export function instantiateWithInstance(): InstantiateResult;
* @param {number | undefined} [length]
* @returns {Uint8Array}
*/
export function digest(algorithm: string, data: Uint8Array, length?: number): Uint8Array;
export function digest(algorithm: string, data: Uint8Array, length?: number): Uint8Array<ArrayBuffer>;
/**
* A context for incrementally computing a digest using a given hash algorithm.
*/
Expand Down Expand Up @@ -74,5 +76,5 @@ export class DigestContext {
* @param {number | undefined} [length]
* @returns {Uint8Array}
*/
digestAndDrop(length?: number): Uint8Array;
digestAndDrop(length?: number): Uint8Array<ArrayBuffer>;
}
2 changes: 2 additions & 0 deletions crypto/crypto.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright 2018-2025 the Deno authors. MIT license.
// This module is browser compatible.

import type { Uint8Array } from "./_uint8array.ts";

/**
* Extensions to the
* {@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Crypto_API | Web Crypto API}
Expand Down
2 changes: 1 addition & 1 deletion encoding/base58_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const testSetBinary = testSetString.map(([data, b58]) => {
}

return [data, b58];
}) as Array<[Uint8Array, string]>;
}) as Array<[Uint8Array<ArrayBuffer>, string]>;

Deno.test("encodeBase58() encodes string", () => {
for (const [input, output] of testSetString) {
Expand Down
8 changes: 8 additions & 0 deletions io/_uint8Array.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
type IsAny<T> = 0 extends (1 & T) ? true : false;
// @ts-ignore Uint8array is not generic in TS < 5.7
type NewUint8Array<T> = Uint8Array<T>;

type IsOld = IsAny<NewUint8Array<ArrayBuffer>>;
type Uint8Array2<T = ArrayBufferLike> = IsOld extends true ? Uint8Array
: NewUint8Array<T>;
export type { Uint8Array2 as Uint8Array };
8 changes: 8 additions & 0 deletions streams/_uint8Array.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
type IsAny<T> = 0 extends (1 & T) ? true : false;
// @ts-ignore Uint8array is not generic in TS < 5.7
type NewUint8Array<T> = Uint8Array<T>;

type IsOld = IsAny<NewUint8Array<ArrayBuffer>>;
type Uint8Array2<T = ArrayBufferLike> = IsOld extends true ? Uint8Array
: NewUint8Array<T>;
export type { Uint8Array2 as Uint8Array };
5 changes: 3 additions & 2 deletions streams/to_array_buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// This module is browser compatible.

import { concat } from "@std/bytes/concat";
import type { Uint8Array } from "./_uint8Array.ts";

/**
* Converts a {@linkcode ReadableStream} of {@linkcode Uint8Array}s to an
Expand All @@ -24,10 +25,10 @@ import { concat } from "@std/bytes/concat";
* ```
*/
export async function toArrayBuffer(
readableStream: ReadableStream<Uint8Array>,
readableStream: ReadableStream<Uint8Array<ArrayBuffer>>,
): Promise<ArrayBuffer> {
const reader = readableStream.getReader();
const chunks: Uint8Array[] = [];
const chunks: Uint8Array<ArrayBuffer>[] = [];

while (true) {
const { done, value } = await reader.read();
Expand Down

0 comments on commit f5c6ee9

Please sign in to comment.