Skip to content

Commit 2a7b241

Browse files
committed
More fixes
1 parent e8611e7 commit 2a7b241

File tree

3 files changed

+213
-37
lines changed

3 files changed

+213
-37
lines changed

src/parsers/typeResolver.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,6 @@ export function resolveType(
3737
typeStack.push(typeId);
3838
}
3939

40-
const typeNodeSymbol =
41-
typeNode && ts.isTypeReferenceNode(typeNode)
42-
? checker.getSymbolAtLocation((typeNode as ts.TypeReferenceNode).typeName)
43-
: undefined;
44-
const namespaces = typeNodeSymbol
45-
? getTypeSymbolNamespaces(typeNodeSymbol)
46-
: getTypeNamespaces(type);
47-
4840
// The following code handles cases where the type is a simple alias of another type (type Alias = SomeType).
4941
// TypeScript resolves the alias automatically, but we want to preserve the original type symbol if it exists.
5042
//
@@ -69,6 +61,8 @@ export function resolveType(
6961
}
7062
}
7163

64+
const namespaces = typeSymbol ? getTypeSymbolNamespaces(typeSymbol) : getTypeNamespaces(type);
65+
7266
try {
7367
if (type.flags & ts.TypeFlags.TypeParameter && type.symbol) {
7468
const declaration = type.symbol.declarations?.[0] as ts.TypeParameterDeclaration | undefined;

test/base-ui-component/input.tsx

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import * as React from 'react';
22

3-
export const BaseUIComponent = React.forwardRef(function BaseUIComponent(
4-
props: BaseUIComponent.Props,
3+
export const BaseUIComponent1 = React.forwardRef(function BaseUIComponent(
4+
props: BaseUIComponent1.Props,
55
ref: React.ForwardedRef<HTMLDivElement>,
66
) {
77
return <div ref={ref} />;
88
});
99

10-
export namespace BaseUIComponent {
10+
export namespace BaseUIComponent1 {
1111
export interface Props extends BaseUIComponentProps<'div', State> {
1212
value?: string;
1313
onValueChange?: (value: string) => void;
@@ -23,36 +23,47 @@ export namespace BaseUIComponent {
2323
}
2424
}
2525

26+
export const BaseUIComponent2 = React.forwardRef(function BaseUIComponent(
27+
props: BaseUIComponent2.Props,
28+
ref: React.ForwardedRef<HTMLDivElement>,
29+
) {
30+
return <div ref={ref} />;
31+
});
32+
33+
export namespace BaseUIComponent2 {
34+
export interface Props extends BaseUIComponentProps<'div', State> {}
35+
36+
export interface State {}
37+
}
38+
2639
type BaseUIComponentProps<
2740
ElementType extends React.ElementType,
2841
State,
29-
RenderFunctionProps = GenericHTMLProps,
30-
> = Omit<WithBaseUIEvent<React.ComponentPropsWithoutRef<ElementType>>, 'className'> & {
31-
/**
32-
* CSS class applied to the element, or a function that
33-
* returns a class based on the component’s state.
34-
*/
42+
RenderFunctionProps = HTMLProps,
43+
> = Omit<
44+
WithBaseUIEvent<React.ComponentPropsWithoutRef<ElementType>>,
45+
'className' | 'color' | 'defaultValue' | 'defaultChecked'
46+
> & {
3547
className?: string | ((state: State) => string);
36-
/**
37-
* Allows you to replace the component’s HTML element
38-
* with a different tag, or compose it with another component.
39-
*
40-
* Accepts a `ReactElement` or a function that returns the element to render.
41-
*/
4248
render?:
4349
| ComponentRenderFn<RenderFunctionProps, State>
4450
| React.ReactElement<Record<string, unknown>>;
4551
};
4652

47-
type ComponentRenderFn<Props, State> = (props: Props, state: State) => React.ReactElement<unknown>;
53+
export type ComponentRenderFn<Props, State> = (
54+
props: Props,
55+
state: State,
56+
) => React.ReactElement<unknown>;
4857

4958
type WithBaseUIEvent<T> = {
5059
[K in keyof T]: WithPreventBaseUIHandler<T[K]>;
5160
};
5261

53-
export type GenericHTMLProps = React.HTMLAttributes<any> & { ref?: React.Ref<any> | undefined };
62+
type HTMLProps<T = any> = React.HTMLAttributes<T> & {
63+
ref?: React.Ref<T> | undefined;
64+
};
5465

55-
export type BaseUIEvent<E extends React.SyntheticEvent<Element, Event>> = E & {
66+
type BaseUIEvent<E extends React.SyntheticEvent<Element, Event>> = E & {
5667
preventBaseUIHandler: () => void;
5768
readonly baseUIHandlerPrevented?: boolean;
5869
};

test/base-ui-component/output.json

Lines changed: 182 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "test/base-ui-component/input",
33
"exports": [
44
{
5-
"name": "BaseUIComponent",
5+
"name": "BaseUIComponent1",
66
"type": {
77
"kind": "component",
88
"name": "ForwardRefExoticComponent",
@@ -113,7 +113,7 @@
113113
"kind": "object",
114114
"name": "State",
115115
"parentNamespaces": [
116-
"BaseUIComponent"
116+
"BaseUIComponent1"
117117
],
118118
"properties": [
119119
{
@@ -147,10 +147,6 @@
147147
],
148148
"parentNamespaces": []
149149
},
150-
"documentation": {
151-
"description": "CSS class applied to the element, or a function that\nreturns a class based on the component’s state.",
152-
"tags": []
153-
},
154150
"optional": true
155151
},
156152
{
@@ -212,7 +208,7 @@
212208
]
213209
}
214210
],
215-
"name": "GenericHTMLProps",
211+
"name": "HTMLProps",
216212
"parentNamespaces": [],
217213
"properties": [
218214
{
@@ -247,7 +243,7 @@
247243
"kind": "object",
248244
"name": "State",
249245
"parentNamespaces": [
250-
"BaseUIComponent"
246+
"BaseUIComponent1"
251247
],
252248
"properties": [
253249
{
@@ -283,9 +279,184 @@
283279
],
284280
"parentNamespaces": []
285281
},
286-
"documentation": {
287-
"description": "Allows you to replace the component’s HTML element\nwith a different tag, or compose it with another component.\n\nAccepts a `ReactElement` or a function that returns the element to render.",
288-
"tags": []
282+
"optional": true
283+
}
284+
]
285+
}
286+
},
287+
{
288+
"name": "BaseUIComponent2",
289+
"type": {
290+
"kind": "component",
291+
"name": "ForwardRefExoticComponent",
292+
"parentNamespaces": [],
293+
"props": [
294+
{
295+
"name": "className",
296+
"type": {
297+
"kind": "union",
298+
"types": [
299+
{
300+
"kind": "intrinsic",
301+
"parentNamespaces": [],
302+
"name": "string"
303+
},
304+
{
305+
"kind": "function",
306+
"parentNamespaces": [],
307+
"callSignatures": [
308+
{
309+
"parameters": [
310+
{
311+
"type": {
312+
"kind": "object",
313+
"name": "State",
314+
"parentNamespaces": [
315+
"BaseUIComponent2"
316+
],
317+
"properties": []
318+
},
319+
"name": "state",
320+
"optional": false
321+
}
322+
],
323+
"returnValueType": {
324+
"kind": "intrinsic",
325+
"parentNamespaces": [],
326+
"name": "string"
327+
}
328+
}
329+
]
330+
},
331+
{
332+
"kind": "intrinsic",
333+
"parentNamespaces": [],
334+
"name": "undefined"
335+
}
336+
],
337+
"parentNamespaces": []
338+
},
339+
"optional": true
340+
},
341+
{
342+
"name": "render",
343+
"type": {
344+
"kind": "union",
345+
"types": [
346+
{
347+
"kind": "reference",
348+
"name": "ReactElement<Record<string, unknown>, string | JSXElementConstructor<any>>",
349+
"parentNamespaces": [
350+
"React"
351+
]
352+
},
353+
{
354+
"kind": "function",
355+
"name": "ComponentRenderFn",
356+
"parentNamespaces": [],
357+
"callSignatures": [
358+
{
359+
"parameters": [
360+
{
361+
"type": {
362+
"kind": "intersection",
363+
"types": [
364+
{
365+
"kind": "reference",
366+
"name": "HTMLAttributes<any>",
367+
"parentNamespaces": [
368+
"React"
369+
]
370+
},
371+
{
372+
"kind": "object",
373+
"parentNamespaces": [],
374+
"properties": [
375+
{
376+
"name": "ref",
377+
"type": {
378+
"kind": "union",
379+
"types": [
380+
{
381+
"kind": "reference",
382+
"name": "Ref<any>",
383+
"parentNamespaces": [
384+
"React"
385+
]
386+
},
387+
{
388+
"kind": "intrinsic",
389+
"parentNamespaces": [],
390+
"name": "undefined"
391+
}
392+
],
393+
"parentNamespaces": []
394+
},
395+
"optional": true
396+
}
397+
]
398+
}
399+
],
400+
"name": "HTMLProps",
401+
"parentNamespaces": [],
402+
"properties": [
403+
{
404+
"name": "ref",
405+
"type": {
406+
"kind": "union",
407+
"types": [
408+
{
409+
"kind": "reference",
410+
"name": "Ref<any>",
411+
"parentNamespaces": [
412+
"React"
413+
]
414+
},
415+
{
416+
"kind": "intrinsic",
417+
"parentNamespaces": [],
418+
"name": "undefined"
419+
}
420+
],
421+
"parentNamespaces": []
422+
},
423+
"optional": true
424+
}
425+
]
426+
},
427+
"name": "props",
428+
"optional": false
429+
},
430+
{
431+
"type": {
432+
"kind": "object",
433+
"name": "State",
434+
"parentNamespaces": [
435+
"BaseUIComponent2"
436+
],
437+
"properties": []
438+
},
439+
"name": "state",
440+
"optional": false
441+
}
442+
],
443+
"returnValueType": {
444+
"kind": "reference",
445+
"name": "ReactElement<unknown, string | JSXElementConstructor<any>>",
446+
"parentNamespaces": [
447+
"React"
448+
]
449+
}
450+
}
451+
]
452+
},
453+
{
454+
"kind": "intrinsic",
455+
"parentNamespaces": [],
456+
"name": "undefined"
457+
}
458+
],
459+
"parentNamespaces": []
289460
},
290461
"optional": true
291462
}

0 commit comments

Comments
 (0)