Skip to content

Commit 05c2b84

Browse files
committed
Fix TypeScript generating broken types
1 parent f7503e3 commit 05c2b84

10 files changed

+89
-36
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,7 @@ coverage/
77
node_modules/
88
test/jsx-*.js
99
yarn.lock
10+
!/lib/automatic-runtime-html.d.ts
11+
!/lib/automatic-runtime-svg.d.ts
1012
!/lib/jsx-automatic.d.ts
1113
!/lib/jsx-classic.d.ts

index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
2-
* @typedef {import('./lib/index.js').Child} Child
3-
* @typedef {import('./lib/index.js').Properties} Properties
4-
* @typedef {import('./lib/index.js').Result} Result
2+
* @typedef {import('./lib/create-h.js').Child} Child
3+
* @typedef {import('./lib/create-h.js').Properties} Properties
4+
* @typedef {import('./lib/create-h.js').Result} Result
55
*/
66

77
export {h, s} from './lib/index.js'

lib/automatic-runtime-html.d.ts

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/* eslint-disable @typescript-eslint/naming-convention */
2+
3+
import type {Element, Root} from 'hast'
4+
import type {Child} from './create-h.js'
5+
import type {JSXProps} from './create-automatic-runtime.js'
6+
7+
export * from './jsx-automatic.js'
8+
9+
export const Fragment: null
10+
11+
export const jsxDEV: {
12+
(
13+
type: null,
14+
properties: {children?: Child},
15+
key?: string | null | undefined
16+
): Root
17+
(type: string, properties: JSXProps, key?: string | null | undefined): Element
18+
}
19+
20+
export const jsxs: {
21+
(
22+
type: null,
23+
properties: {children?: Child},
24+
key?: string | null | undefined
25+
): Root
26+
(type: string, properties: JSXProps, key?: string | null | undefined): Element
27+
}
28+
29+
export const jsx: {
30+
(
31+
type: null,
32+
properties: {children?: Child},
33+
key?: string | null | undefined
34+
): Root
35+
(type: string, properties: JSXProps, key?: string | null | undefined): Element
36+
}

lib/automatic-runtime-html.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Note: types exposed from `automatic-runtime-html.d.ts` because TS has bugs
2+
// when generating types.
13
import {createAutomaticRuntime} from './create-automatic-runtime.js'
24
import {h} from './index.js'
35

lib/automatic-runtime-svg.d.ts

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/* eslint-disable @typescript-eslint/naming-convention */
2+
3+
import type {Element, Root} from 'hast'
4+
import type {Child} from './create-h.js'
5+
import type {JSXProps} from './create-automatic-runtime.js'
6+
7+
export * from './jsx-automatic.js'
8+
9+
export const Fragment: null
10+
11+
export const jsxDEV: {
12+
(
13+
type: null,
14+
properties: {children?: Child},
15+
key?: string | null | undefined
16+
): Root
17+
(type: string, properties: JSXProps, key?: string | null | undefined): Element
18+
}
19+
20+
export const jsxs: {
21+
(
22+
type: null,
23+
properties: {children?: Child},
24+
key?: string | null | undefined
25+
): Root
26+
(type: string, properties: JSXProps, key?: string | null | undefined): Element
27+
}
28+
29+
export const jsx: {
30+
(
31+
type: null,
32+
properties: {children?: Child},
33+
key?: string | null | undefined
34+
): Root
35+
(type: string, properties: JSXProps, key?: string | null | undefined): Element
36+
}

lib/create-automatic-runtime.js

+5-10
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
/**
2-
* @typedef {import('hast').Element} Element
3-
* @typedef {import('hast').Root} Root
4-
*
5-
* @typedef {import('./create-h.js').Child} Child
6-
* @typedef {import('./create-h.js').Properties} Properties
7-
* @typedef {import('./create-h.js').PropertyValue} PropertyValue
8-
* @typedef {import('./create-h.js').Result} Result
9-
* @typedef {import('./create-h.js').Style} Style
10-
* @typedef {import('./create-h.js').createH} CreateH
11-
*
2+
* @import {Element, Root} from 'hast'
3+
* @import {Child, Properties, PropertyValue, Result, Style, createH as CreateH} from './create-h.js'
4+
*/
5+
6+
/**
127
* @typedef {Record<string, Child | PropertyValue | Style>} JSXProps
138
*/
149

lib/create-h.js

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
/**
2-
* @typedef {import('hast').Element} Element
3-
* @typedef {import('hast').Nodes} Nodes
4-
* @typedef {import('hast').RootContent} RootContent
5-
* @typedef {import('hast').Root} Root
6-
*
7-
* @typedef {import('property-information').Info} Info
8-
* @typedef {import('property-information').Schema} Schema
2+
* @import {Element, Nodes, RootContent, Root} from 'hast'
3+
* @import {Info, Schema} from 'property-information'
94
*/
105

116
/**

lib/index.js

-15
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,3 @@
1-
/**
2-
* @typedef {import('./create-h.js').Child} Child
3-
* Acceptable child value.
4-
*/
5-
6-
/**
7-
* @typedef {import('./create-h.js').Properties} Properties
8-
* Acceptable value for element properties.
9-
*/
10-
11-
/**
12-
* @typedef {import('./create-h.js').Result} Result
13-
* Result from a `h` (or `s`) call.
14-
*/
15-
161
// Register the JSX namespace on `h`.
172
/**
183
* @typedef {import('./jsx-classic.js').Element} h.JSX.Element

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"svg-tag-names": "^3.0.0",
2727
"tsd": "^0.31.0",
2828
"type-coverage": "^2.0.0",
29-
"typescript": "~5.4.0",
29+
"typescript": "^5.0.0",
3030
"xo": "^0.60.0"
3131
},
3232
"exports": {

tsconfig.json

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
"include": [
1717
"**/**.js",
1818
"**/**.jsx",
19+
"lib/automatic-runtime-html.d.ts",
20+
"lib/automatic-runtime-svg.d.ts",
1921
"lib/jsx-automatic.d.ts",
2022
"lib/jsx-classic.d.ts"
2123
]

0 commit comments

Comments
 (0)