From 772e1369ad6c281cecd43200532d16ec3b33ce84 Mon Sep 17 00:00:00 2001 From: ehmicky Date: Wed, 5 Jun 2024 09:37:07 +0100 Subject: [PATCH] Improve speed of types (#1118) --- types/return/ignore.d.ts | 4 ++-- types/return/result-ipc.d.ts | 2 +- types/return/result-stdio.d.ts | 3 +-- types/return/result-stdout.d.ts | 4 ++-- types/stdio/option.d.ts | 13 ++++--------- types/stdio/type.d.ts | 6 ++---- types/subprocess/all.d.ts | 2 +- types/subprocess/stdio.d.ts | 3 +-- types/subprocess/stdout.d.ts | 2 +- types/transform/object-mode.d.ts | 6 +++--- 10 files changed, 18 insertions(+), 27 deletions(-) diff --git a/types/return/ignore.d.ts b/types/return/ignore.d.ts index 4a3cf66f75..0df44aaf27 100644 --- a/types/return/ignore.d.ts +++ b/types/return/ignore.d.ts @@ -1,4 +1,4 @@ -import type {NoStreamStdioOption, StdioOptionCommon} from '../stdio/type.js'; +import type {NoStreamStdioOption} from '../stdio/type.js'; import type {IsInputFd} from '../stdio/direction.js'; import type {FdStdioOption} from '../stdio/option.js'; import type {FdSpecificOption} from '../arguments/specific.js'; @@ -22,5 +22,5 @@ export type IgnoresSubprocessOutput< type IgnoresOutput< FdNumber extends string, - StdioOptionType extends StdioOptionCommon, + StdioOptionType, > = StdioOptionType extends NoStreamStdioOption ? true : false; diff --git a/types/return/result-ipc.d.ts b/types/return/result-ipc.d.ts index 99f0f6a20e..f0b7df8e65 100644 --- a/types/return/result-ipc.d.ts +++ b/types/return/result-ipc.d.ts @@ -6,7 +6,7 @@ import type {Message, HasIpc} from '../ipc.js'; // This is empty unless the `ipc` option is `true`. // Also, this is empty if the `buffer` option is `false`. export type ResultIpcOutput< - IsSync extends boolean, + IsSync, OptionsType extends CommonOptions, > = IsSync extends true ? [] diff --git a/types/return/result-stdio.d.ts b/types/return/result-stdio.d.ts index 5319920ca2..9540b20fe5 100644 --- a/types/return/result-stdio.d.ts +++ b/types/return/result-stdio.d.ts @@ -1,4 +1,3 @@ -import type {StdioOptionsArray} from '../stdio/type.js'; import type {StdioOptionNormalizedArray} from '../stdio/array.js'; import type {CommonOptions} from '../arguments/options.js'; import type {ResultStdioNotAll} from './result-stdout.js'; @@ -8,7 +7,7 @@ export type ResultStdioArray = MapResultStdio, OptionsType>; type MapResultStdio< - StdioOptionsArrayType extends StdioOptionsArray, + StdioOptionsArrayType, OptionsType extends CommonOptions, > = { -readonly [FdNumber in keyof StdioOptionsArrayType]: ResultStdioNotAll< diff --git a/types/return/result-stdout.d.ts b/types/return/result-stdout.d.ts index c71081a83d..21732ad34f 100644 --- a/types/return/result-stdout.d.ts +++ b/types/return/result-stdout.d.ts @@ -26,7 +26,7 @@ OptionsType type ResultStdioProperty< ObjectFdNumber extends string, LinesFdNumber extends string, - StreamOutputIgnored extends boolean, + StreamOutputIgnored, OptionsType extends CommonOptions, > = StreamOutputIgnored extends true ? undefined @@ -37,7 +37,7 @@ type ResultStdioProperty< >; type ResultStdioItem< - IsObjectResult extends boolean, + IsObjectResult, LinesOption extends boolean | undefined, Encoding extends CommonOptions['encoding'], > = IsObjectResult extends true ? unknown[] diff --git a/types/stdio/option.d.ts b/types/stdio/option.d.ts index d77e672f3e..0fbe989be6 100644 --- a/types/stdio/option.d.ts +++ b/types/stdio/option.d.ts @@ -1,17 +1,12 @@ import type {CommonOptions} from '../arguments/options.js'; import type {StdioOptionNormalizedArray} from './array.js'; -import type { - StandardStreams, - StdioOptionCommon, - StdioOptionsArray, - StdioOptionsProperty, -} from './type.js'; +import type {StandardStreams, StdioOptionCommon, StdioOptionsArray} from './type.js'; // `options.stdin|stdout|stderr|stdio` for a given file descriptor export type FdStdioOption< FdNumber extends string, OptionsType extends CommonOptions, -> = Extract, StdioOptionCommon>; +> = FdStdioOptionProperty; type FdStdioOptionProperty< FdNumber extends string, @@ -29,11 +24,11 @@ type FdStdioOptionProperty< export type FdStdioArrayOption< FdNumber extends string, OptionsType extends CommonOptions, -> = Extract>, StdioOptionCommon>; +> = FdStdioArrayOptionProperty>; type FdStdioArrayOptionProperty< FdNumber extends string, - StdioOptionsType extends StdioOptionsProperty, + StdioOptionsType, > = string extends FdNumber ? StdioOptionCommon | undefined : StdioOptionsType extends StdioOptionsArray diff --git a/types/stdio/type.d.ts b/types/stdio/type.d.ts index 452361ba18..47cad30f46 100644 --- a/types/stdio/type.d.ts +++ b/types/stdio/type.d.ts @@ -138,7 +138,7 @@ type StdioExtraOptionCommon = | StdoutStderrOptionCommon; // `options.stdin|stdout|stderr|stdio` array items -export type StdioSingleOption< +type StdioSingleOption< IsSync extends boolean = boolean, IsExtra extends boolean = boolean, IsArray extends boolean = boolean, @@ -147,9 +147,7 @@ export type StdioSingleOption< | StdoutStderrSingleOption; // Get `options.stdin|stdout|stderr|stdio` items if it is an array, else keep as is -export type StdioSingleOptionItems< - StdioOptionType extends StdioOptionCommon, -> = StdioOptionType extends readonly StdioSingleOption[] +export type StdioSingleOptionItems = StdioOptionType extends readonly StdioSingleOption[] ? StdioOptionType[number] : StdioOptionType; diff --git a/types/subprocess/all.d.ts b/types/subprocess/all.d.ts index bd4cd83a47..2ef97f001a 100644 --- a/types/subprocess/all.d.ts +++ b/types/subprocess/all.d.ts @@ -8,7 +8,7 @@ export type SubprocessAll = AllStream = IsIgnored extends true ? undefined : Readable; type AllIgnored< - AllOption extends Options['all'], + AllOption, OptionsType extends Options, > = AllOption extends true ? IgnoresSubprocessOutput<'1', OptionsType> extends true diff --git a/types/subprocess/stdio.d.ts b/types/subprocess/stdio.d.ts index 274f41ac94..15b5f8eb02 100644 --- a/types/subprocess/stdio.d.ts +++ b/types/subprocess/stdio.d.ts @@ -1,5 +1,4 @@ import type {StdioOptionNormalizedArray} from '../stdio/array.js'; -import type {StdioOptionsArray} from '../stdio/type.js'; import type {Options} from '../arguments/options.js'; import type {SubprocessStdioStream} from './stdout.js'; @@ -8,7 +7,7 @@ export type SubprocessStdioArray = MapStdioStreams< // We cannot use mapped types because it must be compatible with Node.js `ChildProcess["stdio"]` which uses a tuple with exactly 5 items type MapStdioStreams< - StdioOptionsArrayType extends StdioOptionsArray, + StdioOptionsArrayType, OptionsType extends Options, > = [ SubprocessStdioStream<'0', OptionsType>, diff --git a/types/subprocess/stdout.d.ts b/types/subprocess/stdout.d.ts index c5b90c67a7..41a781cb11 100644 --- a/types/subprocess/stdout.d.ts +++ b/types/subprocess/stdout.d.ts @@ -11,7 +11,7 @@ export type SubprocessStdioStream< type SubprocessStream< FdNumber extends string, - StreamResultIgnored extends boolean, + StreamResultIgnored, OptionsType extends Options, > = StreamResultIgnored extends true ? null diff --git a/types/transform/object-mode.d.ts b/types/transform/object-mode.d.ts index 86f486d305..8c48e2cfd8 100644 --- a/types/transform/object-mode.d.ts +++ b/types/transform/object-mode.d.ts @@ -1,4 +1,4 @@ -import type {StdioSingleOption, StdioOptionCommon, StdioSingleOptionItems} from '../stdio/type.js'; +import type {StdioSingleOptionItems} from '../stdio/type.js'; import type {FdStdioOption} from '../stdio/option.js'; import type {CommonOptions} from '../arguments/options.js'; import type {DuplexTransform, TransformCommon} from './normalize.js'; @@ -10,9 +10,9 @@ export type IsObjectFd< OptionsType extends CommonOptions, > = IsObjectStdioOption>; -type IsObjectStdioOption = IsObjectStdioSingleOption>; +type IsObjectStdioOption = IsObjectStdioSingleOption>; -type IsObjectStdioSingleOption = StdioSingleOptionType extends TransformCommon +type IsObjectStdioSingleOption = StdioSingleOptionType extends TransformCommon ? BooleanObjectMode : StdioSingleOptionType extends DuplexTransform ? StdioSingleOptionType['transform']['readableObjectMode']