Skip to content

TypeScript 4.1 + Preact: TypeScript does not pick up JSX.IntrinsicElements w. jsx: react-jsx #41118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ddprrt opened this issue Oct 15, 2020 · 0 comments · Fixed by #41330
Closed
Assignees
Labels
Bug A bug in TypeScript Domain: JSX/TSX Relates to the JSX parser and emitter Fix Available A PR has been opened for this issue

Comments

@ddprrt
Copy link

ddprrt commented Oct 15, 2020

This is Re: #40502 cc @weswigham @DanielRosenwasser

Using the new JSX transform and Preact as import source, TypeScript doesn't seem to pick up the JSX types that are shipped by Preact. It works as described in #40502 with additionally installed @types/react, but not with the types that come with Preact itself. Daniel suggested filing a new bug 😄

TypeScript Version: 4.1.0-dev.20201015

Search Terms: Preact, JSX, JSX Transform

Code

{
  "compilerOptions": {
    ...
    "jsx": "react-jsx", 
    "jsxImportSource": "preact",
    "types": ["preact/jsx-runtime"],
  }
}

This is the d.ts file that contains the JSX definitions: https://github.com/preactjs/preact/blob/master/jsx-runtime/src/index.d.ts

import { render } from "preact";

function App() {
  return (
    <>
      <h1>Hello World</h1>
    </>
  );
}

const node = document.querySelector("#app");
if (node) {
  render(<App />, node);
}

export default {};

Note: The JSX definitions are in the jsx and jsxDEVnamespaces. I thought this might be an issue. But If I move JSX into the global namespace with

declare global {
  export import JSX = JSXInteral;
}

I get a compile error: Cannot read property 'get' of undefined

Expected behavior: Since TypeScript knows to pull in jsx from preact/jsx-runtime, I'd expect it to pull in JSX types from preact/jsx-runtime/src/index.d.ts.

Actual behavior: JSX element implicitly has type 'any' because no interface 'JSX.IntrinsicElements' exists.ts(7026)

Playground Link: I have a branch in a repo: https://github.com/ddprrt/preact-typescript-starter/tree/jsx-transform

Related Issues: #40502

@weswigham weswigham added Bug A bug in TypeScript Crash For flagging bugs which are compiler or service crashes or unclean exits, rather than bad output labels Oct 22, 2020
@weswigham weswigham self-assigned this Oct 22, 2020
@weswigham weswigham added this to the TypeScript 4.1.1 milestone Oct 22, 2020
@weswigham weswigham added the Domain: JSX/TSX Relates to the JSX parser and emitter label Oct 22, 2020
@weswigham weswigham removed the Crash For flagging bugs which are compiler or service crashes or unclean exits, rather than bad output label Oct 29, 2020
@typescript-bot typescript-bot added the Fix Available A PR has been opened for this issue label Oct 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: JSX/TSX Relates to the JSX parser and emitter Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants