Description
🔎 Search Terms
Typescript Hangs, Memory Leak, VS Code, Prisma, React-Hook-Form,
🕗 Version & Regression Information
-
This is a crash
-
This is the behavior in every version I tried, and I reviewed the FAQ for entries about hanging.
Tested on latest 5.2.2 and 5.3.0-dev-20231012. typescript@next
⏯ Playground Link
https://codesandbox.io/p/sandbox/musing-turing-78vp6j?file=%2Fapp%2Fpage.tsx%3A6%2C33
💻 Code
import { useForm } from "react-hook-form";
import { Prisma } from "@prisma/client";
export default function Home() {
const form = useForm<Prisma.UserCreateInput>();
...
This will hang everything. Typescript won't tsc and intellisense will just sit with "loading" no matter what you hover.
meanwhile this works fine:
import { useForm } from "react-hook-form";
import { Prisma } from "@prisma/client";
export default function Home() {
const form = useForm<>();
...
tsc --noEmit --extendedDiagnostics
will complete in like 3 seconds with this.
🙁 Actual behavior
Typescript won't complete a tsc --noEmit
and intellisense will just sit with "loading" no matter what you hover over. I have seen it once before just set everything to any
With the generated types in the first example - i let it run for 1 hour 59mins on a M1 mac and no output.
You can see the full code example with a minimal repro on the codesandbox link. It also hangs it's intellisense in CSB and won't tsc.
CPU also goes to 100% on both local and CSB
🙂 Expected behavior
Doesn't hang typescript, operates just like if you put any other type in there say
type SomeType = {name: string}
const form = useForm<SomeType>()
Additional information about the issue
Another report by someone else here:
It seems to be anything that comes off the Prisma.* types
Activity
Pyrolistical commentedon Oct 13, 2023
I found the provided codesandbox hard to use as the generated prisma client not included. I've extracted the generated client and put it into
.app/client
Also to note, the repo description in this issue is incomplete. A call to
form.register
is required fortsc
to stall.Here is a much smaller repo https://github.com/Pyrolistical/typescript-repo-56081
npm run build
never completes.I started to cut down
app/client/index.d.ts
, but I gave up after seeing how complicated it is. Also as I cut it down, I noticed tsc does complete. So the extremely recursively types is just really hard for tsc process.PranavSenthilnathan commentedon Oct 13, 2023
Thanks, I was able to repro this. It does look like the prisma generated types have complex template strings so
tsc
is spending a lot of time inremoveStringLiteralsMatchedByTemplateLiterals
and GC. I'll take a look into if we can cut off computation earlier and/or make the checking smarter.PranavSenthilnathan commentedon Oct 16, 2023
Repro without library dependencies (I think the
react-hook-form
types can be simplified more, but this is a good point for me to start investigating from). Prisma generates deeply nested types with a depth of 10+ and branching at each node from 0 to 6+ (not a balanced tree). Still, the type below roughly approximates that and has the same perf issue.Some stats (for
Check<t7>
,Check<t8>
andCheck<t9>
respectively):jakebailey commentedon Oct 20, 2023
Does this bisect to #48044? (https://www.npmjs.com/package/every-ts may be helpful to check, too)
also #52345
PranavSenthilnathan commentedon Oct 27, 2023
It's this PR which introduces string literal and template literal reduction in unions (
every-ts
did help 🙂): #41276jonahallibone commentedon Jul 22, 2024
Is there any movement on this by chance? I also manage to kill TS with react-hook-form and recursive type definitions
ilbertt commentedon Aug 8, 2024
I'm facing a similar problem, using react-hook-form's
useForm
typed with some GraphQL-Codegen's generated mutation input types:Intellisense stops working and
tsc
hangs forever during compilation, as soon as I set the type ofuseForm
.Typescript version: 5.4.5
Platform: MacBook Pro (M3 Pro chip) - macOS Sonoma 14.5
AlexEscalante commentedon Oct 7, 2024
I am facing this issue too with
react-hook-form
.nik-webdevelop commentedon Mar 28, 2025
Same here: tsc hangs forever, and ide(webstorm) intellisense is stuck in the loading state. After closing an ide, intellisense node.js process remains active
Update:
for me, it was failing because of
Icon?: FC<SVGProps<SVGElement>>;
propertyif I comment out the
Icon
property, everything works finets
5.4.2
react18.2.0
rhf7.54.1