question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. Itย collects links to all the places you might be looking at while hunting down a tough bug.

And, if youโ€™re still stuck at the end, weโ€™re happy to hop on a call to see how we can help out.

tsc, tsserver: hangs with large union type and object spread in React HOC (strict mode)

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:11
  • Comments:19 (7 by maintainers)

github_iconTop GitHub Comments

7reactions
natewcommented, Jul 6, 2019

@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.

4reactions
jgozcommented, Feb 27, 2019

@RyanCavanaugh I just disabled all options and re-enabled one-by-one. The server will hang when strict: true is set.

{
  "compileOnSave": false,
  "compilerOptions": {
    "jsx": "react",
    "skipLibCheck": true,
    "strict": true
  }
}
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found