Skip to content

Commit

Permalink
Improve speed of types (#1118)
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Jun 5, 2024
1 parent ca2e813 commit 772e136
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 27 deletions.
4 changes: 2 additions & 2 deletions types/return/ignore.d.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -22,5 +22,5 @@ export type IgnoresSubprocessOutput<

type IgnoresOutput<
FdNumber extends string,
StdioOptionType extends StdioOptionCommon,
StdioOptionType,
> = StdioOptionType extends NoStreamStdioOption<FdNumber> ? true : false;
2 changes: 1 addition & 1 deletion types/return/result-ipc.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
? []
Expand Down
3 changes: 1 addition & 2 deletions types/return/result-stdio.d.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -8,7 +7,7 @@ export type ResultStdioArray<OptionsType extends CommonOptions> =
MapResultStdio<StdioOptionNormalizedArray<OptionsType>, OptionsType>;

type MapResultStdio<
StdioOptionsArrayType extends StdioOptionsArray,
StdioOptionsArrayType,
OptionsType extends CommonOptions,
> = {
-readonly [FdNumber in keyof StdioOptionsArrayType]: ResultStdioNotAll<
Expand Down
4 changes: 2 additions & 2 deletions types/return/result-stdout.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ OptionsType
type ResultStdioProperty<
ObjectFdNumber extends string,
LinesFdNumber extends string,
StreamOutputIgnored extends boolean,
StreamOutputIgnored,
OptionsType extends CommonOptions,
> = StreamOutputIgnored extends true
? undefined
Expand All @@ -37,7 +37,7 @@ type ResultStdioProperty<
>;

type ResultStdioItem<
IsObjectResult extends boolean,
IsObjectResult,
LinesOption extends boolean | undefined,
Encoding extends CommonOptions['encoding'],
> = IsObjectResult extends true ? unknown[]
Expand Down
13 changes: 4 additions & 9 deletions types/stdio/option.d.ts
Original file line number Diff line number Diff line change
@@ -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<FdStdioOptionProperty<FdNumber, OptionsType>, StdioOptionCommon>;
> = FdStdioOptionProperty<FdNumber, OptionsType>;

type FdStdioOptionProperty<
FdNumber extends string,
Expand All @@ -29,11 +24,11 @@ type FdStdioOptionProperty<
export type FdStdioArrayOption<
FdNumber extends string,
OptionsType extends CommonOptions,
> = Extract<FdStdioArrayOptionProperty<FdNumber, StdioOptionNormalizedArray<OptionsType>>, StdioOptionCommon>;
> = FdStdioArrayOptionProperty<FdNumber, StdioOptionNormalizedArray<OptionsType>>;

type FdStdioArrayOptionProperty<
FdNumber extends string,
StdioOptionsType extends StdioOptionsProperty,
StdioOptionsType,
> = string extends FdNumber
? StdioOptionCommon | undefined
: StdioOptionsType extends StdioOptionsArray
Expand Down
6 changes: 2 additions & 4 deletions types/stdio/type.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ type StdioExtraOptionCommon<IsSync extends boolean> =
| StdoutStderrOptionCommon<IsSync, true>;

// `options.stdin|stdout|stderr|stdio` array items
export type StdioSingleOption<
type StdioSingleOption<
IsSync extends boolean = boolean,
IsExtra extends boolean = boolean,
IsArray extends boolean = boolean,
Expand All @@ -147,9 +147,7 @@ export type StdioSingleOption<
| StdoutStderrSingleOption<IsSync, IsExtra, IsArray>;

// 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> = StdioOptionType extends readonly StdioSingleOption[]
? StdioOptionType[number]
: StdioOptionType;

Expand Down
2 changes: 1 addition & 1 deletion types/subprocess/all.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export type SubprocessAll<OptionsType extends Options> = AllStream<AllIgnored<Op
type AllStream<IsIgnored> = IsIgnored extends true ? undefined : Readable;

type AllIgnored<
AllOption extends Options['all'],
AllOption,
OptionsType extends Options,
> = AllOption extends true
? IgnoresSubprocessOutput<'1', OptionsType> extends true
Expand Down
3 changes: 1 addition & 2 deletions types/subprocess/stdio.d.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -8,7 +7,7 @@ export type SubprocessStdioArray<OptionsType extends Options> = 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>,
Expand Down
2 changes: 1 addition & 1 deletion types/subprocess/stdout.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export type SubprocessStdioStream<

type SubprocessStream<
FdNumber extends string,
StreamResultIgnored extends boolean,
StreamResultIgnored,
OptionsType extends Options,
> = StreamResultIgnored extends true
? null
Expand Down
6 changes: 3 additions & 3 deletions types/transform/object-mode.d.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -10,9 +10,9 @@ export type IsObjectFd<
OptionsType extends CommonOptions,
> = IsObjectStdioOption<FdStdioOption<FdNumber, OptionsType>>;

type IsObjectStdioOption<StdioOptionType extends StdioOptionCommon> = IsObjectStdioSingleOption<StdioSingleOptionItems<StdioOptionType>>;
type IsObjectStdioOption<StdioOptionType> = IsObjectStdioSingleOption<StdioSingleOptionItems<StdioOptionType>>;

type IsObjectStdioSingleOption<StdioSingleOptionType extends StdioSingleOption> = StdioSingleOptionType extends TransformCommon
type IsObjectStdioSingleOption<StdioSingleOptionType> = StdioSingleOptionType extends TransformCommon
? BooleanObjectMode<StdioSingleOptionType['objectMode']>
: StdioSingleOptionType extends DuplexTransform
? StdioSingleOptionType['transform']['readableObjectMode']
Expand Down

0 comments on commit 772e136

Please sign in to comment.