Skip to content
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

Locally scoped JSX module #141

Open
brainkim opened this issue Jul 30, 2020 · 2 comments
Open

Locally scoped JSX module #141

brainkim opened this issue Jul 30, 2020 · 2 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@brainkim
Copy link
Member

Crank currently defines the JSX module globally, but it would be nice to have it work locally.

https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#locally-scoped-jsx-namespaces

JSX type checking is driven by definitions in a JSX namespace, for instance JSX.Element for the type of a JSX element, and JSX.IntrinsicElements for built-in elements. Before TypeScript 2.8 the JSX namespace was expected to be in the global namespace, and thus only allowing one to be defined in a project. Starting with TypeScript 2.8 the JSX namespace will be looked under the jsxNamespace (e.g. React) allowing for multiple jsx factories in one compilation. For backward compatibility the global JSX namespace is used as a fallback if none was defined on the factory function. Combined with the per-file @jsx pragma, each file can have a different JSX factory.

Apparently you can do local JSX modules, rather than the global one. I couldn’t figure out how to get it working, because I couldn’t find any examples which don’t use the old namespace syntax.

@brainkim brainkim added enhancement New feature or request help wanted Extra attention is needed labels Jul 30, 2020
@steinitz
Copy link

steinitz commented Sep 26, 2020

I can't claim to fully grasp local JSX modules nor how they relate to Typescript but I love the Crank project and so wanted to help “unstuck” this issue. Is this commit from the Preact project any help? preactjs/preact@f24669f

@brainkim
Copy link
Member Author

@steinitz It sure is interesting! Thanks for the heads up. I still can’t seem to figure out how to get it working. Preact is using a d.ts file, which may or may not be an important difference?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants