Skip to content

Auto import inside a TSX/JSX template should only offer elements that work as JSX elements #57334

@Artur-

Description

@Artur-

Not sure who handles code complete / imports into JSX/TSX files so maybe this would need to be moved somewhere else.

If I add @vaadin/button@24.3.0 and @hilla/react-components@2.3.0 to a project and create the simplest possible react function component

export default function HelloReact() {
  return (
    <button
  );
}

and press cmd-space after button, I see the following
image

The first suggestion is fine, a standard <button> element
The second suggestion is to import import { Button } from "@vaadin/button"; which causes a compilation error

'Button' cannot be used as a JSX component.
  Its type 'typeof Button' is not a valid JSX element type.

so it should not be suggested.

The third import is OK as it is a React element

Then the fourth again is

import { ButtonElement } from "@hilla/react-components/Button.js";

which is

'ButtonElement' cannot be used as a JSX component.
  Its type 'typeof Button' is not a valid JSX element type.

Is there something wrong with the packages? Should they provide more information for VS Code or is this a problem of VS Code where it suggests and imports types that cannot be used in the given location?

If I write <But in IntelliJ I see a list that is more like I would expect
image
although ButtonMixin shows up an as extra item

Metadata

Metadata

Assignees

No one assigned

    Labels

    DeclinedThe issue was declined as something which matches the TypeScript visionSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions