Skip to content

Locally scoped JSX + non-wildcard import doesn't work #23762

@marvinhagemeister

Description

@marvinhagemeister

TypeScript Version: 2.9.0-dev.20180428

Search Terms: jsx, jsxfactory

Code

Over at preact we are currently trying out the new feature of locally scoped JSX namespaces.

// tsconfig.json
{
  "compilerOptions": {
    "jsx": "react",
    "jsxFactory": "h",
  }
}
// This is how most of our users use preact with TS
import { h, Component } from "preact";

export class Foo extends Component {
  render() {
    // <div> has type `any`
    return <div>hey</div>;
  }
}

Slightly rewriting our example we can get this to work:

// tsconfig.json
{
  "compilerOptions": {
    "jsx": "react",
    "jsxFactory": "preact.h",
  }
}
import * as preact from "preact";

export class Foo extends preact.Component {
  render() {
    // <div> now has correct type
    return <div>hey</div>;
  }
}

But that does seem unnecessary.

Expected behavior:

Type of <div> is inferred from the JSX namespace when using jsxFactory: h and import { h } from "preact"

Actual behavior:

<div> is typed as any.

Playground Link:
N/A

Related Issues:

Metadata

Metadata

Assignees

Labels

Working as IntendedThe behavior described is the intended behavior; this is not a bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions