From d256c8ef2c1fc9b16f4b8e26e77fd0044049b018 Mon Sep 17 00:00:00 2001 From: Pelle Wessman Date: Fri, 12 Jul 2024 01:45:32 +0200 Subject: [PATCH] Handle types that implicitly relied on @types/node Follow up to #898 --- source/structured-cloneable.d.ts | 17 +++++++++++++++-- test-d/class.ts | 5 ++--- test-d/multidimensional-array.ts | 2 -- test-d/multidimensional-readonly-array.ts | 2 -- test-d/set-parameter-type.ts | 6 ++++++ test-d/structured-cloneable.ts | 4 ++++ 6 files changed, 27 insertions(+), 9 deletions(-) diff --git a/source/structured-cloneable.d.ts b/source/structured-cloneable.d.ts index e633c7264..a5f44b74f 100644 --- a/source/structured-cloneable.d.ts +++ b/source/structured-cloneable.d.ts @@ -1,5 +1,9 @@ +import type {IfAny} from './if-any'; import type {TypedArray} from './typed-array'; +// Include if the type resolves to an actual type, else do not include it. Enables progressive enhancement +type IncludeIfNotAny = IfAny; + type StructuredCloneablePrimitive = | string | number @@ -18,8 +22,17 @@ type StructuredCloneableData = | Error | RegExp | TypedArray - | Blob - | File; + | IncludeIfNotAny< + // eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error + // @ts-ignore Requires dom or @types/node + Blob + > + // eslint-disable-next-line @typescript-eslint/no-duplicate-type-constituents + | IncludeIfNotAny< + // eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error + // @ts-ignore Requires dom or @types/node@>=20 + File + >; // DOM exclusive types // | AudioData // | CropTarget diff --git a/test-d/class.ts b/test-d/class.ts index fc2f5252d..9d5250ccf 100644 --- a/test-d/class.ts +++ b/test-d/class.ts @@ -2,9 +2,8 @@ import {expectAssignable, expectNotAssignable, expectType} from 'tsd'; import type {Class, Constructor, IsAny} from '../index'; class Foo { - constructor(x: number, y: any) { - console.log(x, y); - } + // eslint-disable-next-line @typescript-eslint/no-useless-constructor, @typescript-eslint/no-empty-function + constructor(_x: number, _y: any) {} // eslint-disable-next-line @typescript-eslint/no-empty-function method(): void {} diff --git a/test-d/multidimensional-array.ts b/test-d/multidimensional-array.ts index 9bf96d078..0e19a121a 100644 --- a/test-d/multidimensional-array.ts +++ b/test-d/multidimensional-array.ts @@ -6,8 +6,6 @@ function createArray(dimensions: T): MultidimensionalArray(dimensions: T): MultidimensionalReadonlyA let array = root; for (let dimension = 1; dimension < dimensions; ++dimension) { - console.log(`Initializing dimension #${dimension}`); - array[0] = []; if (dimension < dimensions - 1) { array = array[0] as unknown[]; diff --git a/test-d/set-parameter-type.ts b/test-d/set-parameter-type.ts index 8416819f3..ad1d5d9f1 100644 --- a/test-d/set-parameter-type.ts +++ b/test-d/set-parameter-type.ts @@ -5,6 +5,8 @@ function function_(_a: number, _b: string, _c: Object, ..._arguments: boolean[]) return null; } +// eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error +// @ts-ignore Global requires @types/node function functionWithThis(this: Global, _a: number) { return null; } @@ -41,5 +43,9 @@ expectType<(a: string) => null>(test5); // Test the function that has `this` parameter declare const testThis: SetParameterType; +// eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error +// @ts-ignore Global requires @types/node expectType<(this: Global, a: string) => null>(testThis); +// eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error +// @ts-ignore global requires @types/node testThis.call(global, '1'); diff --git a/test-d/structured-cloneable.ts b/test-d/structured-cloneable.ts index 5295b4548..f506360c9 100644 --- a/test-d/structured-cloneable.ts +++ b/test-d/structured-cloneable.ts @@ -138,7 +138,11 @@ expectAssignable(new Set()); expectAssignable(new Set>()); // Web/API types +// eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error +// @ts-ignore Requires dom or @types/node@>=20 declare const blob: Blob; expectAssignable(blob); +// eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error +// @ts-ignore Requires dom or @types/node@>=20 declare const file: File; expectAssignable(file);