#VS Code performance

10 messages · Page 1 of 1 (latest)

coarse bear
#

TypeScript Intellisense seems to be loading forever as more Convex Components (2) get added

bleak haloBOT
#

Hi @coarse bear. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

I'm sorry, but there is no specific information in the knowledge sources regarding a direct performance hit specifically from adding exactly "2 Convex Components." However, the knowledge sources do discuss general TypeScript performance issues and "infinite loading" states in large Convex projects.

If your TypeScript Intellisense is taking an excessive amount of time or seems to hang, it is likely due to how Convex relies on TypeScript's type inference. As codebases grow, this inference can become slow [Production > Project Configuration].

Recommended Solutions

  1. Enable Static Code Generation (Beta)
    If you are experiencing language server performance issues, you can switch to static types. This significantly improves autocomplete and incremental typechecking performance by generating fixed versions of your API and data model instead of relying on real-time inference.
    Add this to your convex.json:
    {
      "$schema": "./node_modules/convex/schemas/convex.schema.json",
      "codegen": {
        "staticApi": true,
        "staticDataModel": true
      }
    }
    
    Note: This requires convex dev to be running to update types, and you lose "jump-to-definition" functionality [Production > Project Configuration].
#
  1. Check for "Excessive Deep Type Instantiation" (TS2589)
    This error often occurs when a function returns the result of another Convex function (like a ctx.runQuery result) without explicit typing, creating a circular type loop. To fix this, explicitly type your function return values or the variables receiving the data:

    // Explicitly typing the variable to break the inference loop
    const user: Doc<"users"> = await ctx.runQuery(internal.users.get, { id });
    

    This prevents the TypeScript server from "crashing out" or becoming sluggish [Discord support thread: Excessive Deep Type Instantiation (TS2589); Discord support thread: Type instantiation is excessively deep and possibly infinite.].

  2. IDE Specific Troubleshooting

#

@coarse bear Kapa.ai is still learning and improving, please let me know how I did by reacting below.

coarse bear
#

@bleak halo This is caused by agent.generateObject complaining about Type instantiation is excessively deep and possibly infinite.ts(2589)

bleak haloBOT
#

Let me check the knowledge base for you again. One moment! :books:

#

I'm sorry, but the provided knowledge sources do not contain information about an agent.generateObject function. The knowledge sources explicitly mention that the "Type instantiation is excessively deep and possibly infinite (TS2589)" error in Convex typically occurs when there is circular type inference, particularly when calling and returning results from other Convex functions without explicit typing.

To resolve this error in the context of Convex, you can follow these strategies derived from the knowledge sources:

1. Explicitly Type Return Values

The most common cause is returning a value from ctx.runQuery, ctx.runMutation, or ctx.runAction directly. TypeScript struggles to infer these nested types. You should explicitly type the handler's return value or the variable capturing the result:

// Type the handler return value explicitly
export const myAction = action({
  args: {},
  handler: async (ctx): Promise<string> => {
    const result = await ctx.runQuery(api.myFunctions.getSomething);
    return result.name;
  },
});

// OR type the result variable explicitly
export const myAction = action({
  args: {},
  handler: async (ctx) => {
    const result: { name: string } = await ctx.runQuery(api.myFunctions.getSomething);
    return result.name;
  },
});

[Functions > Actions > The action constructor; Discord support thread: Type instantiation is excessively deep and possibly infinite.]

#

2. Avoid v.any() in Schemas

Several users found that using v.any() inside complex validators, such as v.record(v.string(), v.any()), triggered this specific error. Replacing v.any() with a more specific type (like v.string() or v.json()) often resolves the issue [Discord support thread: Type instantiation is excessively deep and possibly infinite.].

3. Use Static Code Generation

If the error persists across your project due to its size, you can enable static code generation. This stops the deep real-time inference that causes TS2589 by generating fixed types for your API [Production > Project Configuration; Discord support thread: Excessive Deep Type Instantiation (TS2589)].

4. Break Inference with Type Assertions

If you are passing large objects into a function like a "generator," ensure the input object is not relying on the Doc<"table"> or Id<"table"> types, as these are deeply integrated into Convex's generated types and can contribute to the recursion limit [Discord support thread: Very Fun Instance of Type instantiation is excessively deep and possibly infinite.ts(2589); Discord support thread: Type instantiation is excessively deep and possibly infinite.].

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: