Skip to content

Can not use a custom element with a declaration in the tsx file. #48310

@Awen-hub

Description

@Awen-hub

Code

//App.tsx
import React from 'react';

function App() {
  return (
    <div className="App">
      <first></first>
    </div>
  );
}
export default App;
//first.d.ts
declare global {
  namespace JSX {
    interface IntrinsicElements {
      first: any;
    }
  }
}
//tsconfig.json
{
  "compilerOptions": {
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react-jsx"
  },
  "include": [
    "src"
  ]
}

Although I declare the custom element <first /> in first.d.ts, VSCode report an error "Property 'first' does not exist on type 'JSX.IntrinsicElements'." So I need a help to solve this problem.

Enviroment

  • typescript: "4.6.2"

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions