We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
We should have an error path in all pipeable functions so that they can throw when their input is incorrect. Not sure what this would look like yet.
The text was updated successfully, but these errors were encountered:
One possible way we could handle errors would be like this: (playground link)
declare const ErrorMessage: unique symbol; type Error<E> = { [ErrorMessage]: E } // redefine `Pipe` to stop if the accumulator has an error (avoids creating a temporary variable) type Pipe<acc, xs extends Fn[]> = typeof ErrorMessage extends keyof acc ? acc : xs extends [ infer first extends Fn, ...infer rest extends Fn[] ] ? Pipe<Call<first, acc>, rest> : acc;
Which could be used like this:
interface ThrowIfNotStringifiable extends Fn { output: this["args"][0] extends S.Stringifiable ? this["args"][0] : Error<"Expected a string"> } type SayMessage<T> = Pipe<T, [ThrowIfNotStringifiable, S.Prepend<"Message: ">]> type R1 = SayMessage<symbol> // expect `type R1 = { [ErrorMessage]: "Expected a String" }` type R2 = SayMessage<1> // expect `type R2 = "Message: 1"`
Something like this would ensure that the only things with the typeof ErrorMessage key are actually errors and would force pipe to stop.
typeof ErrorMessage
What i am not sure about is what to do for all of the higher-order functions. For example in T.Map:
T.Map
type R3 = Pipe<[symbol, 1], [T.Map<ThrowIfNotStringifiable>]> // ^? [Error<"Expected a string">, 1]
Should we change it so it fails as soon as it encounters one error or should it wait and process the whole tuple and fail silently?
Sorry, something went wrong.
No branches or pull requests
We should have an error path in all pipeable functions so that they can throw when their input is incorrect. Not sure what this would look like yet.
The text was updated successfully, but these errors were encountered: