Skip to content

Commit

Permalink
fix: more ts docs and include private and protected in docs (#678)
Browse files Browse the repository at this point in the history
  • Loading branch information
hugomrdias authored Nov 20, 2020
1 parent e3d3d34 commit a4793cf
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 10 deletions.
8 changes: 1 addition & 7 deletions cmds/ts.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,7 @@ Presets:
\`config\` Prints base config to stdout.
Note:
To provide users types declarations with 0-configuration add following to package.json:
\`\`\`json
"typesVersions": {
"*": { "src/*": ["dist/src/*", "dist/src/*/index"] }
},
\`\`\`
Check out the documentation for JSDoc based TS types here: https://github.com/ipfs/aegir/blob/master/md/ts-jsdoc.md
Supports options forwarding with '--' for more info check https://www.typescriptlang.org/docs/handbook/compiler-options.html
`
Expand Down
36 changes: 35 additions & 1 deletion md/ts-jsdoc.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ aegir ts -p config > tsconfig.json

Add types configuration to your package.json:
```json
"types": "dist/src/index.d.ts",
"typesVersions": {
"*": { "src/*": ["dist/src/*", "dist/src/*/index"] }
},
Expand All @@ -29,7 +30,9 @@ Presets:
`docs` Generates documentation based on type declarations to the `docs` folder.
`config` Prints base config to stdout.
```
## Github Action

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.

## Adding types with JSDoc

Expand Down Expand Up @@ -91,7 +94,7 @@ exports.IPFS = IPFS
```

#### 3. Use a `types.ts` file
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.
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.

```ts
// types.ts
Expand All @@ -102,4 +105,35 @@ export type IntersectionType = Type1 & Type2
// index.js
/** @type { import('./types').IntersectionType } */
const list
```

#### 4. JSDoc comments bad parsing
Some TS tooling may have problems parsing comments if they are not very well divided.

```ts

// BAD - the base typedef can be parsed as a comment for Square

/** @typedef {import('./index') Base} Base */

class Square {}


// GOOD
/** @typedef {import('./index') Base} Base */

/**
* Cool Square class
* @class
*/
class Square {}

// GOOD

class Square {}

module.export = Square

/** @typedef {import('./index') Base} Base */

```
4 changes: 2 additions & 2 deletions src/ts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ const docs = async (forwardOptions, extraInclude) => {
'--excludeExternals',
// '--excludeNotDocumented',
// '--excludeNotExported',
'--excludePrivate',
'--excludeProtected',
// '--excludePrivate',
// '--excludeProtected',
'--includeDeclarations',
'--hideGenerator',
'--includeVersion',
Expand Down

0 comments on commit a4793cf

Please sign in to comment.