Skip to content
Myr

Fix type of result when using the `reject: false` option (#1046)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by ehmicky · committed by GitHub · parent 11bbd9d · Browse files · 10 files+25 added−14 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

10 files+25 added−14 removed

  • other:+25 added−14 removed

10 files+25 added−14 removed

modified:test-d/methods/command.test-d.ts+1 added
modified:test-d/methods/main-async.test-d.ts+1 added
modified:test-d/methods/main-sync.test-d.ts+1 added
49 unmodified lines
50expectType<SyncResult<{}>>(execaSync`unicorns ${false.toString()}`);51expectError(execaSync`unicorns ${false}`);5253expectType<SyncResult<{}>>(execaSync`unicorns ${execaSync`echo foo`}`);54expectType<SyncResult<{}>>(execaSync`unicorns ${execaSync({reject: false})`echo foo`}`);55expectType<SyncResult<{}>>(execaSync`unicorns ${[execaSync`echo foo`, 'bar']}`);
modified:test-d/methods/node.test-d.ts+1 added
49 unmodified lines
50expectType<Result<{}>>(await execaNode`unicorns ${false.toString()}`);51expectError(await execaNode`unicorns ${false}`);5253expectType<Result<{}>>(await execaNode`unicorns ${await execaNode`echo foo`}`);54expectType<Result<{}>>(await execaNode`unicorns ${await execaNode({reject: false})`echo foo`}`);55expectError(await execaNode`unicorns ${execaNode`echo foo`}`);56expectType<Result<{}>>(await execaNode`unicorns ${[await execaNode`echo foo`, 'bar']}`);57expectError(await execaNode`unicorns ${[execaNode`echo foo`, 'bar']}`);58
6 unmodified lines
modified:test-d/methods/script-s.test-d.ts+1 added
59 unmodified lines
60expectType<SyncResult<{}>>($.s`unicorns ${false.toString()}`);61expectError($.s`unicorns ${false}`);6263expectType<SyncResult<{}>>($.s`unicorns ${$.s`echo foo`}`);64expectType<SyncResult<{}>>($.s`unicorns ${$.s({reject: false})`echo foo`}`);65expectType<SyncResult<{}>>($.s`unicorns ${[$.s`echo foo`, 'bar']}`);
modified:test-d/methods/script-sync.test-d.ts+1 added
59 unmodified lines
60expectType<SyncResult<{}>>($.sync`unicorns ${false.toString()}`);61expectError($.sync`unicorns ${false}`);6263expectType<SyncResult<{}>>($.sync`unicorns ${$.sync`echo foo`}`);64expectType<SyncResult<{}>>($.sync`unicorns ${$.sync({reject: false})`echo foo`}`);65expectType<SyncResult<{}>>($.sync`unicorns ${[$.sync`echo foo`, 'bar']}`);
modified:test-d/methods/script.test-d.ts+1 added
49 unmodified lines
50expectType<Result<{}>>(await $`unicorns ${false.toString()}`);51expectError(await $`unicorns ${false}`);5253expectType<Result<{}>>(await $`unicorns ${await $`echo foo`}`);54expectType<Result<{}>>(await $`unicorns ${await $({reject: false})`echo foo`}`);55expectError(await $`unicorns ${$`echo foo`}`);56expectType<Result<{}>>(await $`unicorns ${[await $`echo foo`, 'bar']}`);57expectError(await $`unicorns ${[$`echo foo`, 'bar']}`);
modified:test-d/return/result-reject.test-d.ts+11 added-2 removed
modified:types/methods/template.d.ts+3 added-3 removed
1import type {CommonOptions} from '../arguments/options.js';2import type {CommonResultInstance} from '../return/result.js';1import type {Result, SyncResult} from '../return/result.js';23// Values allowed inside `...${...}...` template syntax4type TemplateExpressionItem =5 | string6 | number8 | CommonResultInstance<boolean, CommonOptions>;7 | Result8 | SyncResult;910export type TemplateExpression = TemplateExpressionItem | readonly TemplateExpressionItem[];1112// `...${...}...` template syntax
4 unmodified lines
modified:types/return/result.d.ts+4 added-9 removed
159 unmodified lines
160 readonly name?: Error['name'];161 stack?: Error['stack'];162}163164export type CommonResultInstance<165 IsSync extends boolean,166 OptionsType extends CommonOptions,167> = InstanceType<typeof CommonResult<IsSync, OptionsType>>;168164type SuccessResult<165 IsSync extends boolean,166 OptionsType extends CommonOptions,172> = CommonResultInstance<IsSync, OptionsType> & OmitErrorIfReject<OptionsType['reject']>;167> = InstanceType<typeof CommonResult<IsSync, OptionsType>> & OmitErrorIfReject<OptionsType['reject']>;168174type OmitErrorIfReject<RejectOption extends CommonOptions['reject']> = RejectOption extends false175 ? {}176 : {[ErrorProperty in ErrorProperties]: never};169type OmitErrorIfReject<RejectOption extends CommonOptions['reject']> = {170 [ErrorProperty in ErrorProperties]: RejectOption extends false ? unknown : never171};172173/**174Result of a subprocess successful execution.175
10 unmodified lines