2024 05 09 resolving error jsx element type any without interface declaration - bizkite-co/handterm GitHub Wiki


original file name: Codeium Chat - tQGLrGXk9BmgXNXZJrF4u1LTzBbzgTXH.md summary: The user encountered an issue where they received an error message stating that a JSX element implicitly has type 'any' because no interface 'JSX.IntrinsicElements' exists. The assistant provided guidance on how to resolve this issue by creating an interface for custom SVG elements in a TypeScript declaration file. The user then asked where to put this declaration, and the assistant recommended putting it in a TypeScript declaration file (.d.ts) that is included in the project, such as a file named svg.d.ts. The assistant also explained how to ensure that this declaration file is included in the TypeScript compilation context. date: 2024-05-09T21:05

Codeium Chat Conversation

Note: This is purely the output of the chat conversation and does not contain any raw data, codebase snippets, etc. used to generate the output.

User at 9:05 pm, May 9, 2024

Explain problem: JSX element implicitly has type 'any' because no interface 'JSX.IntrinsicElements' exists.


Codeium at 9:05 pm, May 9, 2024

The issue "JSX element implicitly has type 'any' because no interface 'JSX.IntrinsicElements' exists" occurs because the JSX element <use> is not a standard HTML element and therefore TypeScript doesn't have a predefined type for it in the JSX.IntrinsicElements interface.

To resolve this, you can create an interface for the custom SVG elements you are using in your project. Here's an example of how you can define an interface for the use element:

declare global {
  namespace JSX {
    interface IntrinsicElements {
      'use': React.SVGProps<SVGUseElement>;
    }
  }
}

You can add this declaration at the beginning of your file or in a separate file to provide TypeScript with the necessary type information for the custom SVG elements like <use> that you are using in your JSX code.

This declaration tells TypeScript that the <use> element in your JSX code should be treated as an SVG element with properties that match SVGUseElement from the React typings.


User at 9:29 pm, May 9, 2024

What file would I put that in?


Codeium at 9:29 pm, May 9, 2024

You can put the interface declaration in a TypeScript declaration file (.d.ts) that is included in your project. For example, you can create a file named svg.d.ts in your project with the following content:

// svg.d.ts
declare global {
  namespace JSX {
    interface IntrinsicElements {
      'use': React.SVGProps<SVGUseElement>;
    }
  }
}

export {};

Make sure that this declaration file is included in your TypeScript compilation context by either being in a directory covered by your tsconfig.json file or by explicitly including it in the files or include arrays of that config file.

Afterwards, TypeScript will use this declaration along with its built-in JSX type definitions to type check your JSX code. If you add this to a .d.ts file that's already part of your project's type declaration structure, it should be picked up automatically by the TypeScript compiler.

⚠️ **GitHub.com Fallback** ⚠️