Closed
Description
TypeScript Version: 3.4.0-dev.20190216
Search Terms: hang higher order union strictFunctionTypes
Code
Note that this code has compilation errors, but that's not important. When invoking tsc
or loading in an editor that uses tsserver
, the compilation hangs/never completes.
import * as React from "react";
const animated: {
[Tag in keyof JSX.IntrinsicElements]: React.ForwardRefExoticComponent<
React.ComponentPropsWithRef<Tag>
>
} = {};
function makeAnimated<T extends React.ReactType>(
comp: T
): React.ForwardRefExoticComponent<React.ComponentPropsWithRef<T>> {
return null as any; // not important
}
export interface UpgradedProps {
show: boolean;
}
export function test<P>(
component: React.ComponentType<P> | keyof React.ReactHTML
): React.ComponentType<P & UpgradedProps> {
// changing to `const Comp: any` un-hangs tsserver
const Comp =
typeof component === "string"
? animated[component]
: makeAnimated(component);
return React.forwardRef<any, P & UpgradeProps>((props, ref) => {
const { show, ...ownProps } = props; // addition of this line causes the hang
return show ? <Comp {...ownProps} ref={ref} /> : null;
});
}
Expected behavior:
Compilation completes (optionally with errors).
Actual behavior:
Compilation hangs.
Repro Link: https://github.com/jgoz/typescript-bug
Related Issues: Didn't find anything recent