-
-
Notifications
You must be signed in to change notification settings - Fork 236
TypeScript: pipeStdout (and other pipeXxx) is optional property #580
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi @koshic,
Lines 31 to 33 in 834e372
Ideally the types would take this into account. Would you be interested in submitting a PR to fix them? |
@ehmicky yeah, let me experiment a bit ) |
As you can see, if we will use current strategy - modify options via generic parameter, and provide all possible combinations as execa definitions, we have to multiply all definitions by 3 (new modifiers: stdout + stdin + all) which makes code unmaintainable: ![]() I see only one way - keep modifiers for options, but produce exact ExecaChildProcess type by additional conditional type wrapper which will work like switch-case statement: O extends { stdin: 'pipe' /* + default value check */} ? { pipeStdout: () => {} } : { } @ehmicky what do you think about it? |
Yes, I think what you're highlighting was the reason I did not implement stricter typing in the first place when adding those pipe methods. I agree with you. I'm not sure if this is what you are describing, but instead of method overloading, type inference could be used. I.e. only define export function execa<EncodingType extends EncodingOption = DefaultEncodingOption>(
file: string,
arguments?: readonly string[],
// EncodingType is now inferred based on the `options` passed as input
options?: Options<EncodingType>
// Which is used to guess whether `result.stdout|stderr|all` is a `string` or a `Buffer`
): ExecaChildProcess<EncodingType extends BufferEncodingOption ? Buffer : string>; What do you think? |
Yes, I mean the same pattern - define function signature once, and use smart generic types. So, I propose to split that task into 2: First PR - to replace overloading with type inference. Not a breaking change, I believe. |
This sounds like a good plan! I do like breaking it down like this, it's going to be easier to review. I actually believe that this might not be a breaking change, because the type will go from Thanks for your help! |
@koshic Would you be interested in doing the second PR discussed above? |
@ehmicky yeah, I need a few days to recover from my illness. |
Thanks @koshic. Take care! 👩⚕️ |
This has been just been fixed in Execa 9.0.0, with the new |
What is the reason to keep it optional?
It can't be user without extra check or '!`:

The text was updated successfully, but these errors were encountered: