-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Closed
Copy link
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug
Description
TypeScript Version: 3.5.2
Search Terms:
Code
import * as React from 'react';
declare type AnyFunction = (...params: any[]) => any;
declare type UnknownFunction = (...params: unknown[]) => unknown;
declare function pipe<A extends unknown[], B>(
ab: (...a: A) => B,
): (...args: A) => B;
declare function pipe<A extends unknown[], B, C>(
ab: (...a: A) => B,
bc: (b: B) => C,
): (...args: A) => C;
declare function pipe(...fns: AnyFunction[]): UnknownFunction;
declare const myHoc: <Props>(
ComposedComponent: React.ComponentType<Props>,
) => React.ComponentType<Props>;
{
const Component = (props: {}) => <div />;
// unknown, expected React.ComponentType<{}>
const result = pipe(
() => Component,
myHoc,
)();
}
{
declare class Component extends React.Component<{}> {}
// unknown, expected React.ComponentType<{}>
const result = pipe(
() => Component,
myHoc,
)();
}
{
declare const Component: React.ComponentType<{}>;
// expected and actual: React.ComponentType<{}>
const result = pipe(
() => Component,
myHoc,
)();
}If we comment out the last pipe overload, it works as expected.
The same problem applies to other generic functions. Here's the smallest test case I could find:
type ComponentType<P> = {
(p: P): null;
p?: P;
};
declare const myHoc: <Props>(
ComposedComponent: ComponentType<Props>,
) => ComponentType<Props>;
{
declare const Component: (props: {}) => null;
// unknown, expected ComponentType<{}>
const result = pipe(
() => Component,
myHoc,
)();
}
{
declare const Component: ComponentType<{}>;
// expected and actual: ComponentType<{}>
const result = pipe(
() => Component,
myHoc,
)();
}Metadata
Metadata
Assignees
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug