Skip to content

JSX elements should not rely on only global JSX.Element type #4195

@tinganho

Description

@tinganho

I find this to be very limiting:

export namespace JSX {
    export interface Element {

    }

    export interface IntrinsicElements {
        div: {};
    }
}

let a = <div></div>;
tsc test.tsx --jsx react --noImplicitAny
test.tsx(2,18): error TS1148: Cannot compile modules unless the '--module' flag is provided.
test.tsx(12,9): error TS2602: JSX element implicitly has type 'any' because the global type 'JSX.Element' does not exist.
test.tsx(12,9): error TS7026: JSX element implicitly has type 'any' because no interface 'JSX.IntrinsicElements' exists
test.tsx(12,10): error TS2304: Cannot find name 'React'.

It doesn't complain if I remove the export keyword. Why does it need to rely on a global type? Can't it not be local? I want to develop a JSX framework and I want to create a local type of JSX.Element etc. and then compile the definition file. I did began with declaring JSX.Element in a d.ts file, but there was some limitation with that approach. Also all my modules is of external type.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DiscussionIssues which may not have code impact

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions