Skip to content

Commit 29663c7

Browse files
committed
Local
1 parent 4015090 commit 29663c7

File tree

4 files changed

+321
-129
lines changed

4 files changed

+321
-129
lines changed

index.js

+56-5
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,69 @@
11
/**
2-
* @typedef {import('./lib/components.js').Components} Components
2+
* @typedef {import('./lib/components.js').Components<JsxElement, JsxElementClass, JsxIntrinsicElements>} Components
3+
* @template JsxElement
4+
* @template JsxElementClass
5+
* @template JsxIntrinsicElements
6+
*/
7+
8+
/**
39
* @typedef {import('./lib/components.js').ExtraProps} ExtraProps
10+
*/
11+
12+
/**
413
* @typedef {import('./lib/index.js').CreateEvaluater} CreateEvaluater
14+
*/
15+
16+
/**
517
* @typedef {import('./lib/index.js').ElementAttributeNameCase} ElementAttributeNameCase
18+
*/
19+
20+
/**
621
* @typedef {import('./lib/index.js').EvaluateExpression} EvaluateExpression
22+
*/
23+
24+
/**
725
* @typedef {import('./lib/index.js').EvaluateProgram} EvaluateProgram
26+
*/
27+
28+
/**
829
* @typedef {import('./lib/index.js').Evaluater} Evaluater
30+
*/
31+
32+
/**
933
* @typedef {import('./lib/index.js').Fragment} Fragment
10-
* @typedef {import('./lib/index.js').Jsx} Jsx
11-
* @typedef {import('./lib/index.js').JsxDev} JsxDev
12-
* @typedef {import('./lib/index.js').Options} Options
13-
* @typedef {import('./lib/index.js').Props} Props
34+
*/
35+
36+
/**
37+
* @typedef {import('./lib/index.js').Jsx<JsxElement>} Jsx
38+
* @template JsxElement
39+
*/
40+
41+
/**
42+
* @typedef {import('./lib/index.js').JsxDev<JsxElement>} JsxDev
43+
* @template JsxElement
44+
*/
45+
46+
/**
47+
* @typedef {import('./lib/index.js').Options<JsxElement, JsxElementClass, JsxIntrinsicElements>} Options
48+
* @template JsxElement
49+
* @template JsxElementClass
50+
* @template JsxIntrinsicElements
51+
*/
52+
53+
/**
54+
* @typedef {import('./lib/index.js').Props<JsxElement>} Props
55+
* @template JsxElement
56+
*/
57+
58+
/**
1459
* @typedef {import('./lib/index.js').Source} Source
60+
*/
61+
62+
/**
1563
* @typedef {import('./lib/index.js').Space} Space
64+
*/
65+
66+
/**
1667
* @typedef {import('./lib/index.js').StylePropertyNameCase} StylePropertyNameCase
1768
*/
1869

lib/components.d.ts

+20-16
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import type {Element} from 'hast'
1010
* @returns
1111
* Result.
1212
*/
13-
export type FunctionComponent<ComponentProps> = (
13+
export type FunctionComponent<JsxElement, ComponentProps> = (
1414
props: ComponentProps
15-
) => JSX.Element | string | null | undefined
15+
) => JsxElement | string | null | undefined
1616

1717
/**
1818
* Class component: given props, returns an instance.
@@ -24,22 +24,22 @@ export type FunctionComponent<ComponentProps> = (
2424
* @returns
2525
* Instance.
2626
*/
27-
export type ClassComponent<ComponentProps> = new (
27+
export type ClassComponent<JsxElementClass, ComponentProps> = new (
2828
props: ComponentProps
29-
) => JSX.ElementClass
29+
) => JsxElementClass
3030

3131
/**
3232
* Function or class component.
3333
*
34-
* You can access props at `JSX.IntrinsicElements`.
35-
* For example, to find props for `a`, use `JSX.IntrinsicElements['a']`.
34+
* You can access props at `LocalJsx.IntrinsicElements`.
35+
* For example, to find props for `a`, use `LocalJsx.IntrinsicElements['a']`.
3636
*
3737
* @typeParam ComponentProps
3838
* Props type.
3939
*/
40-
export type Component<ComponentProps> =
41-
| ClassComponent<ComponentProps>
42-
| FunctionComponent<ComponentProps>
40+
export type Component<JsxElement, JsxElementClass, ComponentProps> =
41+
| ClassComponent<JsxElementClass, ComponentProps>
42+
| FunctionComponent<JsxElement, ComponentProps>
4343

4444
/**
4545
* Extra fields we pass.
@@ -49,17 +49,21 @@ export type ExtraProps = {node?: Element | undefined}
4949
/**
5050
* Possible components to use.
5151
*
52-
* Each key is a tag name typed in `JSX.IntrinsicElements`.
52+
* Each key is a tag name typed in `LocalJsx.IntrinsicElements`.
5353
* Each value is either a different tag name, or a component accepting the
5454
* corresponding props (and an optional `node` prop if `passNode` is on).
5555
*
56-
* You can access props at `JSX.IntrinsicElements`.
57-
* For example, to find props for `a`, use `JSX.IntrinsicElements['a']`.
56+
* You can access props at `LocalJsx.IntrinsicElements`.
57+
* For example, to find props for `a`, use `LocalJsx.IntrinsicElements['a']`.
5858
*/
5959
// Note: this type has to be in `.ts` or `.d.ts`, otherwise TSC hardcodes
6060
// react into the `.d.ts` file.
61-
export type Components = {
62-
[TagName in keyof JSX.IntrinsicElements]:
63-
| Component<JSX.IntrinsicElements[TagName] & ExtraProps>
64-
| keyof JSX.IntrinsicElements
61+
export type Components<JsxElement, JsxElementClass, JsxIntrinsicElements> = {
62+
[TagName in keyof JsxIntrinsicElements]:
63+
| Component<
64+
JsxElement,
65+
JsxElementClass,
66+
JsxIntrinsicElements[TagName] & ExtraProps
67+
>
68+
| keyof JsxIntrinsicElements
6569
}

0 commit comments

Comments
 (0)