Skip to content

Commit a4793cf

Browse files
authored
fix: more ts docs and include private and protected in docs (#678)
1 parent e3d3d34 commit a4793cf

File tree

3 files changed

+38
-10
lines changed

3 files changed

+38
-10
lines changed

cmds/ts.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,7 @@ Presets:
88
\`config\` Prints base config to stdout.
99
1010
Note:
11-
To provide users types declarations with 0-configuration add following to package.json:
12-
13-
\`\`\`json
14-
"typesVersions": {
15-
"*": { "src/*": ["dist/src/*", "dist/src/*/index"] }
16-
},
17-
\`\`\`
11+
Check out the documentation for JSDoc based TS types here: https://github.com/ipfs/aegir/blob/master/md/ts-jsdoc.md
1812
1913
Supports options forwarding with '--' for more info check https://www.typescriptlang.org/docs/handbook/compiler-options.html
2014
`

md/ts-jsdoc.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ aegir ts -p config > tsconfig.json
99

1010
Add types configuration to your package.json:
1111
```json
12+
"types": "dist/src/index.d.ts",
1213
"typesVersions": {
1314
"*": { "src/*": ["dist/src/*", "dist/src/*/index"] }
1415
},
@@ -29,7 +30,9 @@ Presets:
2930
`docs` Generates documentation based on type declarations to the `docs` folder.
3031
`config` Prints base config to stdout.
3132
```
33+
## Github Action
3234

35+
To run the typechecker in the CI you can use this action https://github.com/Gozala/typescript-error-reporter-action and you will get the errors reported inline with the code.
3336

3437
## Adding types with JSDoc
3538

@@ -91,7 +94,7 @@ exports.IPFS = IPFS
9194
```
9295

9396
#### 3. Use a `types.ts` file
94-
When writing types sometimes JSDoc can be cumbersome, impossible, it can output weird type declarations or even broken documentation. Most of these problems can be solved by defining some complex types in typescript in a `types.ts` file.
97+
When writing types JSDoc can sometimes be cumbersome, impossible, it can output weird type declarations or even broken documentation. Most of these problems can be solved by defining some complex types in typescript in a `types.ts` file.
9598

9699
```ts
97100
// types.ts
@@ -102,4 +105,35 @@ export type IntersectionType = Type1 & Type2
102105
// index.js
103106
/** @type { import('./types').IntersectionType } */
104107
const list
108+
```
109+
110+
#### 4. JSDoc comments bad parsing
111+
Some TS tooling may have problems parsing comments if they are not very well divided.
112+
113+
```ts
114+
115+
// BAD - the base typedef can be parsed as a comment for Square
116+
117+
/** @typedef {import('./index') Base} Base */
118+
119+
class Square {}
120+
121+
122+
// GOOD
123+
/** @typedef {import('./index') Base} Base */
124+
125+
/**
126+
* Cool Square class
127+
* @class
128+
*/
129+
class Square {}
130+
131+
// GOOD
132+
133+
class Square {}
134+
135+
module.export = Square
136+
137+
/** @typedef {import('./index') Base} Base */
138+
105139
```

src/ts/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ const docs = async (forwardOptions, extraInclude) => {
145145
'--excludeExternals',
146146
// '--excludeNotDocumented',
147147
// '--excludeNotExported',
148-
'--excludePrivate',
149-
'--excludeProtected',
148+
// '--excludePrivate',
149+
// '--excludeProtected',
150150
'--includeDeclarations',
151151
'--hideGenerator',
152152
'--includeVersion',

0 commit comments

Comments
 (0)