Skip to content

Commit

Permalink
fix(pipe): Ensure that unknown is infered for 9+ arguments. (#6212)
Browse files Browse the repository at this point in the history
  • Loading branch information
benlesh authored Apr 13, 2021
1 parent 5d0552b commit 6fa819b
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 6 deletions.
2 changes: 1 addition & 1 deletion api_guard/dist/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ export declare function pipe<T, A, B, C, D, E, F>(fn1: UnaryFunction<T, A>, fn2:
export declare function pipe<T, A, B, C, D, E, F, G>(fn1: UnaryFunction<T, A>, fn2: UnaryFunction<A, B>, fn3: UnaryFunction<B, C>, fn4: UnaryFunction<C, D>, fn5: UnaryFunction<D, E>, fn6: UnaryFunction<E, F>, fn7: UnaryFunction<F, G>): UnaryFunction<T, G>;
export declare function pipe<T, A, B, C, D, E, F, G, H>(fn1: UnaryFunction<T, A>, fn2: UnaryFunction<A, B>, fn3: UnaryFunction<B, C>, fn4: UnaryFunction<C, D>, fn5: UnaryFunction<D, E>, fn6: UnaryFunction<E, F>, fn7: UnaryFunction<F, G>, fn8: UnaryFunction<G, H>): UnaryFunction<T, H>;
export declare function pipe<T, A, B, C, D, E, F, G, H, I>(fn1: UnaryFunction<T, A>, fn2: UnaryFunction<A, B>, fn3: UnaryFunction<B, C>, fn4: UnaryFunction<C, D>, fn5: UnaryFunction<D, E>, fn6: UnaryFunction<E, F>, fn7: UnaryFunction<F, G>, fn8: UnaryFunction<G, H>, fn9: UnaryFunction<H, I>): UnaryFunction<T, I>;
export declare function pipe<T, A, B, C, D, E, F, G, H, I>(fn1: UnaryFunction<T, A>, fn2: UnaryFunction<A, B>, fn3: UnaryFunction<B, C>, fn4: UnaryFunction<C, D>, fn5: UnaryFunction<D, E>, fn6: UnaryFunction<E, F>, fn7: UnaryFunction<F, G>, fn8: UnaryFunction<G, H>, fn9: UnaryFunction<H, I>, ...fns: UnaryFunction<any, any>[]): UnaryFunction<T, {}>;
export declare function pipe<T, A, B, C, D, E, F, G, H, I>(fn1: UnaryFunction<T, A>, fn2: UnaryFunction<A, B>, fn3: UnaryFunction<B, C>, fn4: UnaryFunction<C, D>, fn5: UnaryFunction<D, E>, fn6: UnaryFunction<E, F>, fn7: UnaryFunction<F, G>, fn8: UnaryFunction<G, H>, fn9: UnaryFunction<H, I>, ...fns: UnaryFunction<any, any>[]): UnaryFunction<T, unknown>;

export declare const queue: QueueScheduler;

Expand Down
4 changes: 2 additions & 2 deletions spec-dtslint/util/pipe-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ it('should infer for 9 arguments', () => {
const o = pipe(a('0', '1'), a('1', '2'), a('2', '3'), a('3', '4'), a('4', '5'), a('5', '6'), a('6', '7'), a('7', '8'), a('8', '9')); // $ExpectType UnaryFunction<"0", "9">
});

it('should infer {} for more than 9 arguments', () => {
const o = pipe(a('0', '1'), a('1', '2'), a('2', '3'), a('3', '4'), a('4', '5'), a('5', '6'), a('6', '7'), a('7', '8'), a('8', '9'), a('9', '10')); // $ExpectType UnaryFunction<"0", {}>
it('should infer unknown for more than 9 arguments', () => {
const o = pipe(a('0', '1'), a('1', '2'), a('2', '3'), a('3', '4'), a('4', '5'), a('5', '6'), a('6', '7'), a('7', '8'), a('8', '9'), a('9', '10')); // $ExpectType UnaryFunction<"0", unknown>
});

it('should require a type assertion for more than 9 arguments', () => {
Expand Down
4 changes: 1 addition & 3 deletions src/internal/util/pipe.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { identity } from './identity';
import { UnaryFunction } from '../types';

/* tslint:disable:max-line-length */
export function pipe(): typeof identity;
export function pipe<T, A>(fn1: UnaryFunction<T, A>): UnaryFunction<T, A>;
export function pipe<T, A, B>(fn1: UnaryFunction<T, A>, fn2: UnaryFunction<A, B>): UnaryFunction<T, B>;
Expand Down Expand Up @@ -68,8 +67,7 @@ export function pipe<T, A, B, C, D, E, F, G, H, I>(
fn8: UnaryFunction<G, H>,
fn9: UnaryFunction<H, I>,
...fns: UnaryFunction<any, any>[]
): UnaryFunction<T, {}>;
/* tslint:enable:max-line-length */
): UnaryFunction<T, unknown>;

export function pipe(...fns: Array<UnaryFunction<any, any>>): UnaryFunction<any, any> {
return pipeFromArray(fns);
Expand Down

0 comments on commit 6fa819b

Please sign in to comment.