tsc, tsserver: hangs with large union type and object spread in React HOC (strict mode)
See original GitHub issueTypeScript 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
Issue Analytics
- State:
- Created 5 years ago
- Reactions:11
- Comments:19 (7 by maintainers)
Top Results From Across the Web
Typescript Box produces a union type that is too complex to ...
Expression produces a union type that is too complex to represent.ts(2590). As I can see here, this is due to having both @mui/material...
Read more >Porting 30K lines of code from Flow to TypeScript - Hacker News
I work on a >100KLOC Flow codebase and I can tell you the type checker is anything but instant.
Read more >Untitled
Hold on tight boney james, Travis tritt album down the road i go. Cdf enduro uzerche 2014, Chlumetzky catering bad ischl, Skylanders trap...
Read more >Documentation - TypeScript 4.4
Similarly, we can write an index signature with template string pattern type. One use of this might be to exempt properties starting with...
Read more >Untitled
Union bank check card, Rozdrabniacz bosch mmr 1501, 100 rms how many watts, Uconn hdfs careers, Am602 asus driver, Dojo vs jquery speed!...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@aleclarson oh! Is anyone else getting what Iโm getting the ? Last couple months VSCode as been nearly unusable (with no extensions), autocomplete takes a couple seconds, cursor and text input lags often and sometimes they spike to a freeze. This is on a pretty powerful new laptop.
@RyanCavanaugh I just disabled all options and re-enabled one-by-one. The server will hang when
strict: true
is set.