Skip to content

Commit f4aa6b6

Browse files
committed
Typescript: Ignore fields marked with @internal tag
1 parent b9e99df commit f4aa6b6

File tree

3 files changed

+32
-12
lines changed

3 files changed

+32
-12
lines changed

.changeset/gorgeous-flies-burn.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+
Ignore fields marked with `@internal` tag

packages/typescript/src/generate/base.ts

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,30 @@ export interface DocEntry {
1717
interface EntryContext {
1818
program: ts.Program;
1919
checker: ts.TypeChecker;
20-
options: GenerateOptions;
20+
transform?: Transformer;
2121
type: ts.Type;
2222
symbol: ts.Symbol;
2323
}
2424

25+
type Transformer = (
26+
this: EntryContext,
27+
entry: DocEntry,
28+
propertyType: ts.Type,
29+
propertySymbol: ts.Symbol,
30+
) => void;
31+
2532
export interface GenerateOptions {
33+
/**
34+
* Allow fields with `@internal` tag
35+
*
36+
* @defaultValue false
37+
*/
38+
allowInternal?: boolean;
39+
2640
/**
2741
* Modify output property entry
2842
*/
29-
transform?: (
30-
this: EntryContext,
31-
entry: DocEntry,
32-
propertyType: ts.Type,
33-
propertySymbol: ts.Symbol,
34-
) => void;
43+
transform?: Transformer;
3544
}
3645

3746
export interface GenerateDocumentationOptions extends GenerateOptions {
@@ -66,13 +75,13 @@ export function generateDocumentation(
6675
export function generate(
6776
program: ts.Program,
6877
symbol: ts.Symbol,
69-
options: GenerateOptions,
78+
{ allowInternal = false, transform }: GenerateOptions,
7079
): GeneratedDoc {
7180
const checker = program.getTypeChecker();
7281
const type = checker.getDeclaredTypeOfSymbol(symbol);
7382
const entryContext: EntryContext = {
7483
checker,
75-
options,
84+
transform,
7685
program,
7786
type,
7887
symbol,
@@ -85,12 +94,13 @@ export function generate(
8594
),
8695
entries: type
8796
.getProperties()
88-
.map((prop) => getDocEntry(prop, entryContext)),
97+
.map((prop) => getDocEntry(prop, entryContext))
98+
.filter((entry) => allowInternal || !('internal' in entry.tags)),
8999
};
90100
}
91101

92102
function getDocEntry(prop: ts.Symbol, context: EntryContext): DocEntry {
93-
const { checker, options } = context;
103+
const { checker, transform } = context;
94104
const subType = checker.getTypeOfSymbol(prop);
95105
const tags = Object.fromEntries(
96106
prop
@@ -119,7 +129,7 @@ function getDocEntry(prop: ts.Symbol, context: EntryContext): DocEntry {
119129
type: typeName,
120130
};
121131

122-
options.transform?.call(context, entry, subType, prop);
132+
transform?.call(context, entry, subType, prop);
123133

124134
return entry;
125135
}

packages/typescript/test/fixtures/test-2.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,9 @@ export interface Player {
1919
* Returned by API
2020
*/
2121
age: number;
22+
23+
/**
24+
* @internal
25+
*/
26+
privateValue: string
2227
}

0 commit comments

Comments
 (0)