Skip to content

Commit

Permalink
feat: generics parameter docs (#71)
Browse files Browse the repository at this point in the history
* feat: call signature for interfaces

* fix: line errors

* fix: updates snapshot

* feat: type parameters
  • Loading branch information
kazupon committed May 21, 2021
1 parent 3dbb7e8 commit f339c30
Show file tree
Hide file tree
Showing 6 changed files with 1,511 additions and 1,285 deletions.
17 changes: 12 additions & 5 deletions examples/packages/library1/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export type B = number

/**
* A dumb type
*
* @typeParam T - a type template
*/
export type DumbType<T> = { foo: T }

Expand Down Expand Up @@ -124,6 +126,7 @@ export function add(a: number, b: number): number {
* un dummy
*
* @param dummy - A dummy
* @typeParam T - a type template
*/
export function undumbify<T>(dummy: DumbType<T>): T {
return dummy.foo
Expand Down Expand Up @@ -161,7 +164,10 @@ export interface AddCallable {
* @param a target 1
* @param b target 2
* @returns added value
*
*
* @typeParam A - a target 1 Type
* @typeParam B - a target 2 Type
*
* @public
*/
<A extends number = number, B extends number = number>(a: A, b: B): number
Expand All @@ -170,7 +176,6 @@ export interface AddCallable {
* @param a target 1
* @param b target 2
* @returns added string value
*
* @public
*/
<A extends number = number, B extends number = number>(a: A, b: B): string
Expand All @@ -196,6 +201,8 @@ export interface MyOptions {
* @remarks
* This is remarks of Calculator class
*
* @typeParam T - A type of calcualator class
*
* @example
* ```javascript
* const c = new Calculator()
Expand All @@ -205,18 +212,18 @@ export interface MyOptions {
*
* @public
*/
export class Calculator implements Calculatable {
export class Calculator<T> implements Calculatable {
/**
* calcurator types
*/
type: string
type: T

/**
* Conssutructor of usage
*
* @param type calculator type
*/
constructor(type: string) {
constructor(type: T) {
this.type = type
}

Expand Down
81 changes: 81 additions & 0 deletions src/processor/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,33 @@ export function buildFunctionContent(
builder.newline()
}

// type params
if (docs.typeParams && docs.typeParams.count > 0) {
builder.pushline(`**Type parameters**`)
builder.newline()
builder.pushline(`| Parameter | Description |`)
builder.pushline(`| --- | --- |`)
for (const p of docs.typeParams.blocks) {
builder.pushline(
`| ${p.parameterName} | ${
p.content
? getDocSectionContent(
model,
pkg,
// @ts-ignore TODO:
p.content,
item,
style,
resolver,
customTags
)
: ''
} |`
)
}
builder.newline()
}

// parameters
const itemParam = item as ApiParameterListMixin
if (itemParam.parameters) {
Expand Down Expand Up @@ -369,6 +396,33 @@ export function buildContentForClassinizable(
builder.newline()
}

// type params
if (docs.typeParams && docs.typeParams.count > 0) {
builder.pushline(`**Type parameters**`)
builder.newline()
builder.pushline(`| Parameter | Description |`)
builder.pushline(`| --- | --- |`)
for (const p of docs.typeParams.blocks) {
builder.pushline(
`| ${p.parameterName} | ${
p.content
? getDocSectionContent(
model,
pkg,
// @ts-ignore TODO:
p.content,
item,
style,
resolver,
customTags
)
: ''
} |`
)
}
builder.newline()
}

// parameters
const itemParam = item as ApiParameterListMixin
if (
Expand Down Expand Up @@ -722,6 +776,33 @@ export function buildTypeAliasContent(
builder.newline()
}

// type params
if (docs.typeParams && docs.typeParams.count > 0) {
builder.pushline(`**Type parameters**`)
builder.newline()
builder.pushline(`| Parameter | Description |`)
builder.pushline(`| --- | --- |`)
for (const p of docs.typeParams.blocks) {
builder.pushline(
`| ${p.parameterName} | ${
p.content
? getDocSectionContent(
model,
pkg,
// @ts-ignore TODO:
p.content,
item,
style,
resolver,
customTags
)
: ''
} |`
)
}
builder.newline()
}

// remarks
if (docs.remarksBlock) {
builder.pushline(`${'#'.repeat(base + 1)} Remarks`)
Expand Down

0 comments on commit f339c30

Please sign in to comment.