Skip to content

Commit 64a9475

Browse files
stibel5ZYSZ3K
authored andcommitted
fix(egeneral): add comment, remove any casting
1 parent 5fd7942 commit 64a9475

File tree

2 files changed

+62
-26
lines changed

2 files changed

+62
-26
lines changed

apps/website/docusaurus.config.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ module.exports = {
6767
plugins: plugins,
6868
trailingSlash: false,
6969
themeConfig: {
70-
// Algolia search disabled - requires appId in Docusaurus v3
71-
// To re-enable, add appId to the algolia config:
70+
// TODO: if we want to re-enable Algolia, we need to get a new key and app id.
7271
// algolia: {
7372
// appId: 'YOUR_APP_ID',
7473
// apiKey: '4f9905bd301a15034820905263f47dda',

apps/website/src/typeui/renderReflection.tsx

Lines changed: 61 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,10 @@ function renderPropsAndMethods(
9393
params: Params
9494
) {
9595
const props = reflection.children?.filter(
96-
(c) =>
97-
(c as any).kindString === 'Property' || c.kind === ReflectionKind.Property
96+
(c) => c.kind === ReflectionKind.Property || getKindString(c) === 'Property'
9897
);
9998
const methods = reflection.children?.filter(
100-
(c) =>
101-
(c as any).kindString === 'Method' || c.kind === ReflectionKind.Method
99+
(c) => c.kind === ReflectionKind.Method || getKindString(c) === 'Method'
102100
);
103101
return (
104102
<>
@@ -128,6 +126,38 @@ function renderFunction(
128126
);
129127
}
130128

129+
function getKindString(
130+
reflection: JSONOutput.DeclarationReflection
131+
): string | undefined {
132+
if ('kindString' in reflection) {
133+
const obj = reflection as unknown as { kindString?: string };
134+
return obj.kindString;
135+
}
136+
return undefined;
137+
}
138+
139+
function getDefaultValue(
140+
reflection: JSONOutput.DeclarationReflection
141+
): unknown {
142+
if ('defaultValue' in reflection) {
143+
const obj = reflection as unknown as { defaultValue?: unknown };
144+
return obj.defaultValue;
145+
}
146+
return undefined;
147+
}
148+
149+
function getTypeParameter(
150+
reflection: JSONOutput.DeclarationReflection
151+
): JSONOutput.TypeParameterReflection[] | undefined {
152+
if ('typeParameter' in reflection) {
153+
const obj = reflection as unknown as {
154+
typeParameter?: JSONOutput.TypeParameterReflection[];
155+
};
156+
return obj.typeParameter;
157+
}
158+
return undefined;
159+
}
160+
131161
// Helper function to get ReflectionKind from reflection, with fallback to kindString
132162
function getReflectionKind(
133163
reflection: JSONOutput.DeclarationReflection
@@ -153,18 +183,19 @@ function getReflectionKind(
153183
'Call signature': ReflectionKind.CallSignature
154184
};
155185

156-
if ((reflection as any).kindString) {
157-
return kindStringMap[(reflection as any).kindString] || null;
186+
const kindString = getKindString(reflection);
187+
if (kindString) {
188+
return kindStringMap[kindString] || null;
158189
}
159190

160191
// Infer from reflection properties (for TypeDoc 0.28 compatibility)
161192
if (reflection.signatures) {
162193
return ReflectionKind.Function;
163194
}
164-
if (typeof (reflection as any).defaultValue !== 'undefined') {
195+
if (getDefaultValue(reflection) !== undefined) {
165196
return ReflectionKind.EnumMember;
166197
}
167-
if ((reflection as any).type) {
198+
if (reflection.type) {
168199
return ReflectionKind.Property;
169200
}
170201
return ReflectionKind.TypeAlias;
@@ -194,9 +225,7 @@ export default function renderReflection(
194225
<code> </code>
195226
<TokenPlain>{reflection.name}</TokenPlain>
196227
{renderTypeParameters(
197-
(reflection as any).typeParameter ||
198-
reflection.typeParameters ||
199-
[],
228+
getTypeParameter(reflection) || reflection.typeParameters || [],
200229
params.withTypeParamsLinks()
201230
)}
202231
<TokenPunctuation>{' = '}</TokenPunctuation>
@@ -230,9 +259,7 @@ export default function renderReflection(
230259
<code> </code>
231260
<TokenPlain>{reflection.name}</TokenPlain>
232261
{renderTypeParameters(
233-
(reflection as any).typeParameter ||
234-
reflection.typeParameters ||
235-
[],
262+
getTypeParameter(reflection) || reflection.typeParameters || [],
236263
params.withTypeParamsLinks()
237264
)}
238265
<code> </code>
@@ -253,9 +280,7 @@ export default function renderReflection(
253280
<code> </code>
254281
<TokenPlain>{reflection.name}</TokenPlain>
255282
{renderTypeParameters(
256-
(reflection as any).typeParameter ||
257-
reflection.typeParameters ||
258-
[],
283+
getTypeParameter(reflection) || reflection.typeParameters || [],
259284
params.withTypeParamsLinks()
260285
)}
261286
<code> </code>
@@ -304,7 +329,7 @@ export default function renderReflection(
304329
if (reflection.signatures) {
305330
return renderArrowSignatures(reflection.signatures, params);
306331
}
307-
let ret: any = null;
332+
let ret: React.ReactElement | null = null;
308333
for (const group of reflection.groups!) {
309334
if (group.title === 'Properties') {
310335
const props = reflection.children.filter((c) =>
@@ -344,14 +369,26 @@ export default function renderReflection(
344369
</>
345370
);
346371
}
347-
// Fallback: try to cast if it's actually a SignatureReflection
372+
// Fallback: check if reflection has SignatureReflection properties
373+
if (
374+
'type' in reflection &&
375+
(reflection as unknown as JSONOutput.SignatureReflection).type
376+
) {
377+
return (
378+
<>
379+
{renderConst(reflection.name)}
380+
{renderArrowSignature(
381+
reflection as unknown as JSONOutput.SignatureReflection,
382+
params
383+
)}
384+
</>
385+
);
386+
}
387+
// If no valid signature found, return fallback
348388
return (
349389
<>
350390
{renderConst(reflection.name)}
351-
{renderArrowSignature(
352-
reflection as any as JSONOutput.SignatureReflection,
353-
params
354-
)}
391+
<TokenKeyword>any</TokenKeyword>
355392
</>
356393
);
357394
case ReflectionKind.Variable:
@@ -378,7 +415,7 @@ export default function renderReflection(
378415
default:
379416
console.warn('Unhandled Declaration Reflection, falling back to any', {
380417
kind: kind,
381-
kindString: (reflection as any).kindString,
418+
kindString: getKindString(reflection),
382419
reflection
383420
});
384421
// Try to render as a property if it has a type

0 commit comments

Comments
 (0)