Fix complexity bug with types (#1037)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by ehmicky · committed by GitHub · parent 398d090 · Browse files · 4 files·+20 added−18 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+20 added−18 removed
- other:+20 added−18 removed
Provenance
- Commit
6cc519b- Tree
ed5ebc7- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
398d090
4 files changed+20 added−18 removed
modified:types/stdio/direction.d.ts+3 added-9 removed
12234567891011111213141516171812import type {CommonOptions} from '../arguments/options.js';import type {StdinOptionCommon, StdoutStderrOptionCommon, StdioOptionCommon} from './type.js';import type {Intersects} from '../utils.js';import type {StdioSingleOptionItems, InputStdioOption} from './type.js';import type {FdStdioArrayOption} from './option.js';
// Whether `result.stdio[FdNumber]` is an input streamexport type IsInputFd< FdNumber extends string, OptionsType extends CommonOptions = CommonOptions,> = FdNumber extends '0' ? true : IsInputDescriptor<FdStdioArrayOption<FdNumber, OptionsType>>;
// Whether `result.stdio[3+]` is an input streamtype IsInputDescriptor<StdioOptionType extends StdioOptionCommon> = StdioOptionType extends StdinOptionCommon ? StdioOptionType extends StdoutStderrOptionCommon ? false : true : false; : Intersects<StdioSingleOptionItems<FdStdioArrayOption<FdNumber, OptionsType>>, InputStdioOption>;modified:types/stdio/type.d.ts+11 added-4 removed
65 unmodified lines6667686970717273707172737475767766 unmodified lines14414514614714814915015115215315415515615715813 unmodified lines65 unmodified linestype ProcessStdinFd = {readonly fd?: 0};type ProcessStdoutStderrFd = {readonly fd?: 1 | 2};
// Values available only in `options.stdin|stdio`type InputStdioOption< IsSync extends boolean, IsExtra extends boolean, IsArray extends boolean,export type InputStdioOption< IsSync extends boolean = boolean, IsExtra extends boolean = boolean, IsArray extends boolean = boolean,> = | 0 | Unless<And<IsSync, IsExtra>, Uint8Array | IterableObject<IsArray>> | Unless<And<IsSync, IsArray>, Readable & ProcessStdinFd>66 unmodified lines> = | StdinSingleOption<IsSync, IsExtra, IsArray> | StdoutStderrSingleOption<IsSync, IsExtra, IsArray>;
// Get `options.stdin|stdout|stderr|stdio` items if it is an array, else keep as isexport type StdioSingleOptionItems< StdioOptionType extends StdioOptionCommon,> = StdioOptionType extends readonly StdioSingleOption[] ? StdioOptionType[number] : StdioOptionType;
// `options.stdin|stdout|stderr|stdio`export type StdioOptionCommon<IsSync extends boolean = boolean> = | StdinOptionCommon<IsSync> | StdoutStderrOptionCommon<IsSync>;13 unmodified linesmodified:types/transform/object-mode.d.ts+2 added-5 removed
1-import type {StdioSingleOption, StdioOptionCommon} from '../stdio/type.js';1+import type {StdioSingleOption, StdioOptionCommon, StdioSingleOptionItems} from '../stdio/type.js';2 import type {FdStdioOption} from '../stdio/option.js';3 import type {CommonOptions} from '../arguments/options.js';4 import type {DuplexTransform} from './normalize.js';5 3 unmodified lines9 FdNumber extends string,10 OptionsType extends CommonOptions = CommonOptions,11 > = IsObjectStdioOption<FdStdioOption<FdNumber, OptionsType>>;12 13-type IsObjectStdioOption<StdioOptionType extends StdioOptionCommon> = IsObjectStdioSingleOption<StdioOptionType extends readonly StdioSingleOption[]14- ? StdioOptionType[number]15- : StdioOptionType16->;13+type IsObjectStdioOption<StdioOptionType extends StdioOptionCommon> = IsObjectStdioSingleOption<StdioSingleOptionItems<StdioOptionType>>;14 15 type IsObjectStdioSingleOption<StdioSingleOptionType extends StdioSingleOption> = StdioSingleOptionType extends {objectMode?: boolean}16 ? BooleanObjectMode<StdioSingleOptionType['objectMode']>17 : StdioSingleOptionType extends DuplexTransform4 unmodified linesmodified:types/utils.d.ts+4 added
5 unmodified lines6789101112135 unmodified lines
export type Unless<Condition extends boolean, ThenValue, ElseValue = never> = Condition extends true ? ElseValue : ThenValue;
export type AndUnless<Condition extends boolean, ThenValue, ElseValue = unknown> = Condition extends true ? ElseValue : ThenValue;
// Whether any of T's union element is the same as one of U's union element.// `&` does not work here.export type Intersects<T, U> = true extends (T extends U ? true : false) ? true : false;