Fix type of `result.ipc` (#1071)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by ehmicky · committed by GitHub · parent 3ab34de · Browse files · 3 files·+23 added−10 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+23 added−10 removed
- other:+23 added−10 removed
Provenance
- Commit
69152ec- Tree
843419d- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
3ab34de
3 files changed+23 added−10 removed
modified:docs/api.md+1 added-1 removed
467 unmodified lines468 [More info.](output.md#additional-file-descriptors)469 470 ### result.ipc471 472-_Type_: `unknown[]`472+_Type_: [`Message[]`](ipc.md#message-type)473 474 All the messages [sent by the subprocess](#sendmessagemessage) to the current process.475 476 This is empty unless the [`ipc`](#optionsipc) option is `true`. Also, this is empty if the [`buffer`](#optionsbuffer) option is `false`.618 unmodified linesmodified:test-d/return/result-ipc.ts+14 added-7 removed
4 unmodified lines5678910111212131415151617181920212223242526277 unmodified lines353637383233394041424337444546474849434450515253544 unmodified lines type Result, type SyncResult, type ExecaError, type ExecaSyncError, type Message,} from '../../index.js';
const ipcResult = await execa('unicorns', {ipc: true});expectType<unknown[]>(ipcResult.ipc);expectType<Array<Message<'advanced'>>>(ipcResult.ipc);
const ipcFdResult = await execa('unicorns', {ipc: true, buffer: {stdout: false}});expectType<unknown[]>(ipcFdResult.ipc);expectType<Array<Message<'advanced'>>>(ipcFdResult.ipc);
const advancedResult = await execa('unicorns', {ipc: true, serialization: 'advanced'});expectType<Array<Message<'advanced'>>>(advancedResult.ipc);
const jsonResult = await execa('unicorns', {ipc: true, serialization: 'json'});expectType<Array<Message<'json'>>>(jsonResult.ipc);
const falseIpcResult = await execa('unicorns', {ipc: false});expectType<[]>(falseIpcResult.ipc);
const noIpcResult = await execa('unicorns');7 unmodified lines
const syncResult = execaSync('unicorns');expectType<[]>(syncResult.ipc);
expectType<unknown[] | []>({} as Result['ipc']);expectAssignable<unknown[]>({} as Result['ipc']);expectType<Message[] | []>({} as Result['ipc']);expectAssignable<Message[]>({} as Result['ipc']);expectType<[]>({} as unknown as SyncResult['ipc']);
const ipcError = new Error('.') as ExecaError<{ipc: true}>;expectType<unknown[]>(ipcError.ipc);expectType<Array<Message<'advanced'>>>(ipcError.ipc);
const ipcFalseError = new Error('.') as ExecaError<{ipc: false}>;expectType<[]>(ipcFalseError.ipc);
const asyncError = new Error('.') as ExecaError;expectType<unknown[] | []>(asyncError.ipc);expectAssignable<unknown[]>(asyncError.ipc);expectType<Message[] | []>(asyncError.ipc);expectAssignable<Message[]>(asyncError.ipc);
const syncError = new Error('.') as ExecaSyncError;expectType<[]>(syncError.ipc);modified:types/return/result-ipc.d.ts+8 added-2 removed
1234567891011121213141516171819202122232425202627import type {FdSpecificOption} from '../arguments/specific.js';import type {CommonOptions} from '../arguments/options.js';import type {Message} from '../ipc.js';
// `result.ipc`// This is empty unless the `ipc` option is `true`.// Also, this is empty if the `buffer` option is `false`.export type ResultIpc< IsSync extends boolean, OptionsType extends CommonOptions,> = IsSync extends true ? [] : ResultIpcAsync<FdSpecificOption<OptionsType['buffer'], 'ipc'>, OptionsType['ipc']>; : ResultIpcAsync< FdSpecificOption<OptionsType['buffer'], 'ipc'>, OptionsType['ipc'], OptionsType['serialization'] >;
type ResultIpcAsync< BufferOption extends boolean | undefined, IpcOption extends boolean | undefined, SerializationOption extends CommonOptions['serialization'],> = BufferOption extends false ? [] : IpcOption extends true ? unknown[] ? Array<Message<SerializationOption>> : [];