Skip to content

Commit c042eb7

Browse files
committed
TypeScript: Fix private class members
1 parent 6070b03 commit c042eb7

File tree

3 files changed

+96
-2
lines changed

3 files changed

+96
-2
lines changed

.changeset/khaki-rings-know.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'fumadocs-typescript': patch
3+
---
4+
5+
Fix private class members

packages/typescript/src/generate/base.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,22 @@ export function generate(
111111
.getType()
112112
.getProperties()
113113
.map((prop) => getDocEntry(prop, entryContext))
114-
.filter((entry) => allowInternal || !('internal' in entry.tags)),
114+
.filter(
115+
(entry) => entry && (allowInternal || !('internal' in entry.tags)),
116+
) as DocEntry[],
115117
};
116118
}
117119

118-
function getDocEntry(prop: TsSymbol, context: EntryContext): DocEntry {
120+
function getDocEntry(
121+
prop: TsSymbol,
122+
context: EntryContext,
123+
): DocEntry | undefined {
119124
const { transform, program } = context;
125+
126+
if (context.type.isClass() && prop.getName().startsWith('#')) {
127+
return;
128+
}
129+
120130
const subType = program
121131
.getTypeChecker()
122132
.getTypeOfSymbolAtLocation(prop, context.declaration);
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import { expect, test } from 'vitest';
2+
import { generateDocumentation } from '@/generate/base';
3+
4+
test('class members', () => {
5+
const out = generateDocumentation(
6+
'index.ts',
7+
'MyClass',
8+
`
9+
export class MyClass {
10+
#name: string;
11+
private test: string;
12+
age: number;
13+
14+
constructor(name: string) {
15+
this.#name = name;
16+
}
17+
}
18+
`,
19+
);
20+
21+
expect(out).toMatchInlineSnapshot(`
22+
[
23+
{
24+
"description": "",
25+
"entries": [
26+
{
27+
"description": "",
28+
"name": "test",
29+
"tags": {},
30+
"type": "string",
31+
},
32+
{
33+
"description": "",
34+
"name": "age",
35+
"tags": {},
36+
"type": "number",
37+
},
38+
],
39+
"name": "MyClass",
40+
},
41+
]
42+
`);
43+
});
44+
45+
test('interface members', () => {
46+
const out = generateDocumentation(
47+
'index.ts',
48+
'MyInterface',
49+
`
50+
export interface MyInterface {
51+
"#name": string;
52+
age: number
53+
}
54+
`,
55+
);
56+
57+
expect(out).toMatchInlineSnapshot(`
58+
[
59+
{
60+
"description": "",
61+
"entries": [
62+
{
63+
"description": "",
64+
"name": "#name",
65+
"tags": {},
66+
"type": "string",
67+
},
68+
{
69+
"description": "",
70+
"name": "age",
71+
"tags": {},
72+
"type": "number",
73+
},
74+
],
75+
"name": "MyInterface",
76+
},
77+
]
78+
`);
79+
});

0 commit comments

Comments
 (0)