Skip to content
This repository was archived by the owner on Oct 9, 2021. It is now read-only.

Commit d254a3a

Browse files
committed
feat!: Move JSX from global namespace to vhtml.JSX
Instead of injecting the `JSX` namespace as a global symbol, move it under a new namespace named `vhtml`. This `vhtml` namespace is merged with the `vhtml()` function. Library consumers can access it as `.JSX`: import h from "vhtml"; type A = h.JSX.Element; The `JSX` namespace can also be imported directly: import h, {JSX} from "vhtml"; type A = JSX.Element; This should allow vhtml-powered JSX code to be used together with other JSX-based libraries, such as React. It _should_ solve the issue: - developit/vhtml#19 (comment) Background: TypeScript 2.8 supports locally scoping the `JSX` namespace. This allows a package to use multiple libraries that expose different variations of the `JSX` namespace without conflicts. See: - https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#locally-scoped-jsx-namespaces - microsoft/TypeScript#22207 Note: This does not allow you to use two JSX-based libraries together in a single module. No transpiler that I know of supports this use case.
1 parent e384740 commit d254a3a

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

input/vhtml.d.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ declare function vhtml<Props, Children extends any[]>(
4646
*/
4747
type HtmlElementAttr<
4848
Tag extends string
49-
> = (Tag extends keyof JSX.IntrinsicElements
50-
? JSX.IntrinsicElements[Tag]
49+
> = (Tag extends keyof vhtml.JSX.IntrinsicElements
50+
? vhtml.JSX.IntrinsicElements[Tag]
5151
: {}) & {
5252
dangerouslySetInnerHTML?: { __html: string };
5353
[attr: string]: any;
@@ -99,7 +99,7 @@ type ComponentPropTransform<TComp, TProps> = SafeEmptyType<
9999
? never
100100
: {});
101101

102-
declare global {
102+
declare namespace vhtml {
103103
namespace JSX {
104104
type Element = string;
105105

src/generate-types.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,9 @@ function generateJsxTypesForVhtml(
210210

211211
// Since extracting interfaces from reactSourceFile takes very long, let's do
212212
// this first so that we can fail fast if the input source file doesn't have
213-
// `global.JSX`.
213+
// `vhtml.JSX`.
214214
const inputJsxNamespace = inputSourceFile
215-
.getModuleOrThrow("global")
215+
.getModuleOrThrow("vhtml")
216216
.getModuleOrThrow("JSX");
217217

218218
const extractedInterfaceNodes: (

0 commit comments

Comments
 (0)