From f4329a9c989201d69b0e54497eba4f3e6c095abc Mon Sep 17 00:00:00 2001 From: tgreyuk Date: Thu, 27 May 2021 21:48:42 +0100 Subject: [PATCH] feat: UI fixes and readability enhancements (#230) --- .../resources/helpers/declaration-title.ts | 27 ++- .../src/resources/helpers/if-show-returns.ts | 11 + .../src/resources/helpers/member-symbol.ts | 3 - .../src/resources/helpers/parameter-table.ts | 67 ++--- .../src/resources/helpers/returns.ts | 16 -- .../src/resources/helpers/signature-title.ts | 50 ++-- .../src/resources/helpers/type-and-parent.ts | 50 ++-- .../resources/helpers/type-parameter-table.ts | 71 ++++++ .../src/resources/helpers/type.ts | 23 +- .../resources/partials/member.declaration.hbs | 34 ++- .../resources/partials/member.signature.hbs | 64 ++++- .../src/resources/partials/member.sources.hbs | 30 ++- .../src/resources/templates/reflection.hbs | 8 +- .../__snapshots__/declarations.spec.ts.snap | 154 +++++++----- .../specs/__snapshots__/generics.spec.ts.snap | 57 +++++ .../__snapshots__/hierarchy.spec.ts.snap | 8 +- .../specs/__snapshots__/members.spec.ts.snap | 22 +- .../__snapshots__/reflections.spec.ts.snap | 33 +-- .../__snapshots__/signatures.spec.ts.snap | 229 +++++++++++------- .../specs/__snapshots__/sources.spec.ts.snap | 29 ++- .../specs/__snapshots__/types.spec.ts.snap | 20 +- .../test/specs/declarations.spec.ts | 42 +++- .../test/specs/generics.spec.ts | 51 ++++ .../test/specs/reflections.spec.ts | 16 +- .../test/specs/signatures.spec.ts | 23 +- .../test/specs/sources.spec.ts | 11 +- .../test/stubs/src/comments.ts | 13 +- .../test/stubs/src/declarations.ts | 37 ++- .../test/stubs/src/generics.ts | 29 +++ .../test/stubs/src/index.ts | 1 + .../test/stubs/src/reflections.ts | 10 - .../test/stubs/src/signatures.ts | 14 +- .../test/stubs/src/types.ts | 8 +- 33 files changed, 835 insertions(+), 426 deletions(-) create mode 100644 packages/typedoc-plugin-markdown/src/resources/helpers/if-show-returns.ts delete mode 100644 packages/typedoc-plugin-markdown/src/resources/helpers/returns.ts create mode 100644 packages/typedoc-plugin-markdown/src/resources/helpers/type-parameter-table.ts create mode 100644 packages/typedoc-plugin-markdown/test/specs/__snapshots__/generics.spec.ts.snap create mode 100644 packages/typedoc-plugin-markdown/test/specs/generics.spec.ts create mode 100644 packages/typedoc-plugin-markdown/test/stubs/src/generics.ts diff --git a/packages/typedoc-plugin-markdown/src/resources/helpers/declaration-title.ts b/packages/typedoc-plugin-markdown/src/resources/helpers/declaration-title.ts index d7d2b36a3..6830b5527 100644 --- a/packages/typedoc-plugin-markdown/src/resources/helpers/declaration-title.ts +++ b/packages/typedoc-plugin-markdown/src/resources/helpers/declaration-title.ts @@ -1,9 +1,9 @@ +import { DeclarationReflection, ParameterReflection } from 'typedoc'; import { - DeclarationReflection, - ParameterReflection, + LiteralType, ReflectionKind, -} from 'typedoc'; -import { ReflectionType } from 'typedoc/dist/lib/models'; + ReflectionType, +} from 'typedoc/dist/lib/models'; import { escape } from './escape'; import { memberSymbol } from './member-symbol'; @@ -27,15 +27,26 @@ export function declarationTitle( ); } - md.push(`: ${this.parent?.kindOf(ReflectionKind.Enum) ? '' : getType(this)}`); + if (!this.parent?.kindOf(ReflectionKind.Enum)) { + md.push(getType(this)); + } - if (this.defaultValue && this.defaultValue !== '...') { - md.push(`= ${stripLineBreaks(escape(stripComments(this.defaultValue)))}`); + if ( + !(this.type instanceof LiteralType) && + this.defaultValue && + this.defaultValue !== '...' + ) { + md.push(` = ${stripLineBreaks(escape(stripComments(this.defaultValue)))}`); } return md.join(''); } function getType(reflection: ParameterReflection | DeclarationReflection) { const reflectionType = reflection.type as ReflectionType; - return type.call(reflectionType ? reflectionType : reflection, 'object'); + if (reflectionType && reflectionType.declaration?.children) { + return ': `Object`'; + } + return ( + ': ' + type.call(reflectionType ? reflectionType : reflection, 'object') + ); } diff --git a/packages/typedoc-plugin-markdown/src/resources/helpers/if-show-returns.ts b/packages/typedoc-plugin-markdown/src/resources/helpers/if-show-returns.ts new file mode 100644 index 000000000..f2e3f02b1 --- /dev/null +++ b/packages/typedoc-plugin-markdown/src/resources/helpers/if-show-returns.ts @@ -0,0 +1,11 @@ +import * as Handlebars from 'handlebars'; +import { ReflectionKind, SignatureReflection } from 'typedoc'; + +export function ifShowReturns( + this: SignatureReflection, + options: Handlebars.HelperOptions, +) { + return this.type && !this.parent?.kindOf(ReflectionKind.Constructor) + ? options.fn(this) + : options.inverse(this); +} diff --git a/packages/typedoc-plugin-markdown/src/resources/helpers/member-symbol.ts b/packages/typedoc-plugin-markdown/src/resources/helpers/member-symbol.ts index 0142ee2c0..310e530ec 100644 --- a/packages/typedoc-plugin-markdown/src/resources/helpers/member-symbol.ts +++ b/packages/typedoc-plugin-markdown/src/resources/helpers/member-symbol.ts @@ -3,9 +3,6 @@ import { DeclarationReflection, ReflectionKind } from 'typedoc'; export function memberSymbol(this: DeclarationReflection) { const isStatic = this.flags && this.flags.isStatic; - if (this.kind === ReflectionKind.ConstructorSignature) { - return '\\+'; - } if (this.kind === ReflectionKind.CallSignature) { return '▸'; } diff --git a/packages/typedoc-plugin-markdown/src/resources/helpers/parameter-table.ts b/packages/typedoc-plugin-markdown/src/resources/helpers/parameter-table.ts index e540c1def..26baf1031 100644 --- a/packages/typedoc-plugin-markdown/src/resources/helpers/parameter-table.ts +++ b/packages/typedoc-plugin-markdown/src/resources/helpers/parameter-table.ts @@ -1,18 +1,11 @@ -import { - ParameterReflection, - ReflectionKind, - TypeParameterReflection, -} from 'typedoc'; +import { ParameterReflection, ReflectionKind } from 'typedoc'; import { comment } from './comment'; import { escape } from './escape'; import { stripLineBreaks } from './strip-line-breaks'; import { type } from './type'; -export function parameterTable( - this: ParameterReflection[] & TypeParameterReflection[], - kind: 'typeParameters' | 'parameters', -) { +export function parameterTable(this: ParameterReflection[]) { const flattenParams = (current: any) => { return current.type?.declaration?.children?.reduce( (acc: any, child: any) => { @@ -37,13 +30,11 @@ export function parameterTable( return table( this.reduce((acc: any, current: any) => parseParams(current, acc), []), - kind, ); } -function table(parameters: any, kind: 'typeParameters' | 'parameters') { - const showDefaults = hasDefaultValues(kind, parameters); - const showTypes = kind === 'parameters' ? true : hasTypes(parameters); +function table(parameters: any) { + const showDefaults = hasDefaultValues(parameters); const comments = parameters.map( (param) => @@ -51,14 +42,10 @@ function table(parameters: any, kind: 'typeParameters' | 'parameters') { ); const hasComments = !comments.every((value) => !value); - const headers = ['Name']; - - if (showTypes) { - headers.push('Type'); - } + const headers = ['Name', 'Type']; if (showDefaults) { - headers.push(kind === 'parameters' ? 'Default value' : 'Default'); + headers.push('Default value'); } if (hasComments) { @@ -74,9 +61,7 @@ function table(parameters: any, kind: 'typeParameters' | 'parameters') { }\``, ); - if (showTypes) { - row.push(parameter.type ? type.call(parameter.type, 'object') : '-'); - } + row.push(type.call(parameter.type, 'object')); if (showDefaults) { row.push(getDefaultValue(parameter)); @@ -102,37 +87,19 @@ function table(parameters: any, kind: 'typeParameters' | 'parameters') { return output; } -function getDefaultValue( - parameter: ParameterReflection | TypeParameterReflection, -) { - if (parameter instanceof TypeParameterReflection) { - return parameter.default ? type.call(parameter.default) : '-'; - } +function getDefaultValue(parameter: ParameterReflection) { return parameter.defaultValue && parameter.defaultValue !== '...' ? escape(parameter.defaultValue) - : '-'; + : '`undefined`'; } -function hasDefaultValues( - kind: 'typeParameters' | 'parameters', - parameters: ParameterReflection[] | TypeParameterReflection[], -) { - const defaultValues = - kind === 'parameters' - ? (parameters as ParameterReflection[]).map( - (param) => param.defaultValue !== '...' && !!param.defaultValue, - ) - : (parameters as TypeParameterReflection[]).map( - (param) => !!param.default, - ); - return !defaultValues.every((value) => !value); -} - -function hasTypes( - parameters: TypeParameterReflection[] | ParameterReflection[], -) { - const types = (parameters as TypeParameterReflection[]).map( - (param) => !!param.type, +function hasDefaultValues(parameters: ParameterReflection[]) { + const defaultValues = (parameters as ParameterReflection[]).map( + (param) => + param.defaultValue !== '{}' && + param.defaultValue !== '...' && + !!param.defaultValue, ); - return !types.every((value) => !value); + + return !defaultValues.every((value) => !value); } diff --git a/packages/typedoc-plugin-markdown/src/resources/helpers/returns.ts b/packages/typedoc-plugin-markdown/src/resources/helpers/returns.ts deleted file mode 100644 index 3179fb494..000000000 --- a/packages/typedoc-plugin-markdown/src/resources/helpers/returns.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { ReflectionType } from 'typedoc/dist/lib/models'; - -import { propertyTable } from './property-table'; -import { type } from './type'; - -export function returns(this: ReflectionType) { - const md = [`**Returns:** ${type.call(this, 'object')}`]; - if ( - this instanceof ReflectionType && - this.declaration && - this.declaration.children - ) { - md.push(propertyTable.call(this.declaration.children)); - } - return md.join('\n\n'); -} diff --git a/packages/typedoc-plugin-markdown/src/resources/helpers/signature-title.ts b/packages/typedoc-plugin-markdown/src/resources/helpers/signature-title.ts index 85382817f..b0effaae4 100644 --- a/packages/typedoc-plugin-markdown/src/resources/helpers/signature-title.ts +++ b/packages/typedoc-plugin-markdown/src/resources/helpers/signature-title.ts @@ -1,4 +1,9 @@ -import { SignatureReflection } from 'typedoc'; +import { + ParameterReflection, + ReflectionKind, + SignatureReflection, +} from 'typedoc'; + import { memberSymbol } from './member-symbol'; import { type } from './type'; @@ -18,7 +23,7 @@ export function signatureTitle( } if (accessor) { - md.push(`${accessor} **${this.name}**`); + md.push(`\`${accessor}\` **${this.name}**`); } else if (this.name !== '__call' && this.name !== '__type') { md.push(`**${this.name}**`); } @@ -30,26 +35,29 @@ export function signatureTitle( .join(', ')}\\>`, ); } + md.push(`(${getParameters(this.parameters)})`); - const params = this.parameters - ? this.parameters - .map((param) => { - const paramsmd: string[] = []; - if (param.flags.isRest) { - paramsmd.push('...'); - } - paramsmd.push(`\`${param.name}`); - if (param.flags.isOptional || param.defaultValue) { - paramsmd.push('?'); - } - paramsmd.push(`\`: ${type.call(param.type, true)}`); - return paramsmd.join(''); - }) - .join(', ') - : ''; - md.push(`(${params})`); - if (this.type) { - md.push(`: ${type.call(this.type, 'all')}`); + if (this.type && !this.parent?.kindOf(ReflectionKind.Constructor)) { + md.push(`: ${type.call(this.type, 'object')}`); } return md.join('') + (standalone ? '\n' : ''); } + +const getParameters = ( + parameters: ParameterReflection[] = [], + backticks = true, +) => { + return parameters + .map((param) => { + const paramsmd: string[] = []; + if (param.flags.isRest) { + paramsmd.push('...'); + } + const paramItem = `${param.name}${ + param.flags.isOptional || param.defaultValue ? '?' : '' + }`; + paramsmd.push(backticks ? `\`${paramItem}\`` : paramItem); + return paramsmd.join(''); + }) + .join(', '); +}; diff --git a/packages/typedoc-plugin-markdown/src/resources/helpers/type-and-parent.ts b/packages/typedoc-plugin-markdown/src/resources/helpers/type-and-parent.ts index 83b12f6b9..95a952d81 100644 --- a/packages/typedoc-plugin-markdown/src/resources/helpers/type-and-parent.ts +++ b/packages/typedoc-plugin-markdown/src/resources/helpers/type-and-parent.ts @@ -11,45 +11,28 @@ export function typeAndParent(this: ArrayType | ReferenceType) { } else { if (this.reflection) { const md: string[] = []; - const parentReflection = this.reflection.parent; if (this.reflection instanceof SignatureReflection) { - if ( - parentReflection && - parentReflection.parent && - parentReflection.parent.url - ) { + if (this.reflection.parent?.parent?.url) { md.push( - `[${ - parentReflection.parent.name - }](${MarkdownTheme.HANDLEBARS.helpers.relativeURL( - parentReflection.parent.url, - )})`, + getUrl( + this.reflection.parent.parent.name, + this.reflection.parent.parent.url, + ), ); - } else if (parentReflection && parentReflection.parent) { - md.push(parentReflection.parent.name); + if (this.reflection.parent.url) { + md.push( + getUrl(this.reflection.parent.name, this.reflection.parent.url), + ); + } } } else { - if (parentReflection && parentReflection.url) { + if (this.reflection.parent?.url) { md.push( - `[${ - parentReflection.name - }](${MarkdownTheme.HANDLEBARS.helpers.relativeURL( - parentReflection.url, - )})`, + getUrl(this.reflection.parent.name, this.reflection.parent.url), ); - } else if (parentReflection) { - md.push(parentReflection.name); - } - if (this.reflection.url) { - md.push( - `[${ - this.reflection.name - }](${MarkdownTheme.HANDLEBARS.helpers.relativeURL( - this.reflection.url, - )})`, - ); - } else { - md.push(this.reflection.name); + if (this.reflection.url) { + md.push(getUrl(this.reflection.name, this.reflection.url)); + } } } return md.join('.'); @@ -60,3 +43,6 @@ export function typeAndParent(this: ArrayType | ReferenceType) { } return 'void'; } + +const getUrl = (name: string, url: string) => + `[${name}](${MarkdownTheme.HANDLEBARS.helpers.relativeURL(url)})`; diff --git a/packages/typedoc-plugin-markdown/src/resources/helpers/type-parameter-table.ts b/packages/typedoc-plugin-markdown/src/resources/helpers/type-parameter-table.ts new file mode 100644 index 000000000..ce9d6dccb --- /dev/null +++ b/packages/typedoc-plugin-markdown/src/resources/helpers/type-parameter-table.ts @@ -0,0 +1,71 @@ +import { TypeParameterReflection } from 'typedoc'; + +import { comment } from './comment'; +import { stripLineBreaks } from './strip-line-breaks'; +import { type } from './type'; + +export function typeParameterTable(this: TypeParameterReflection[]) { + return table(this); +} + +function table(parameters: any) { + const showTypeCol = hasTypes(parameters); + const comments = parameters.map( + (param) => + !!param.comment?.text?.trim() || !!param.comment?.shortText?.trim(), + ); + const hasComments = !comments.every((value) => !value); + + const headers = ['Name']; + + if (showTypeCol) { + headers.push('Type'); + } + + if (hasComments) { + headers.push('Description'); + } + + const rows = parameters.map((parameter) => { + const row: string[] = []; + + row.push(`\`${parameter.name}\``); + + if (showTypeCol) { + const typeCol: string[] = [`\`${parameter.name}\``]; + if (parameter.type) { + typeCol.push(`: ${type.call(parameter.type, 'object')}`); + } + if (parameter.default) { + typeCol.push(` = ${type.call(parameter.default)}`); + } + row.push(typeCol.join('')); + } + + if (hasComments) { + if (parameter.comment) { + row.push( + stripLineBreaks(comment.call(parameter.comment)).replace( + /\|/g, + '\\|', + ), + ); + } else { + row.push('-'); + } + } + return `| ${row.join(' | ')} |\n`; + }); + + const output = `\n| ${headers.join(' | ')} |\n| ${headers + .map(() => ':------') + .join(' | ')} |\n${rows.join('')}`; + return output; +} + +function hasTypes(parameters: TypeParameterReflection[]) { + const types = (parameters as TypeParameterReflection[]).map( + (param) => !!param.type || !!param.default, + ); + return !types.every((value) => !value); +} diff --git a/packages/typedoc-plugin-markdown/src/resources/helpers/type.ts b/packages/typedoc-plugin-markdown/src/resources/helpers/type.ts index 75a3d27f8..9f91f1f8a 100644 --- a/packages/typedoc-plugin-markdown/src/resources/helpers/type.ts +++ b/packages/typedoc-plugin-markdown/src/resources/helpers/type.ts @@ -120,11 +120,11 @@ function getLiteralType(model: LiteralType) { function getReflectionType(model: DeclarationReflection, collapse: Collapse) { if (model.signatures) { return collapse === 'function' || collapse === 'all' - ? '*function*' + ? `\`fn\`` : getFunctionType(model.signatures); } return collapse === 'object' || collapse === 'all' - ? '*object*' + ? `\`Object\`` : getDeclarationType(model); } @@ -178,7 +178,6 @@ export function getFunctionType(modelSignatures: SignatureReflection[]) { }) : []; const returns = type.call(fn.type); - return typeParams + `(${params.join(', ')}) => ${returns}`; }); return functions.join(''); @@ -189,23 +188,23 @@ function getReferenceType(model: ReferenceType, emphasis) { const reflection = model.reflection && model.reflection.url ? [ - `[*${escape( + `[${escape( model.reflection.name, - )}*](${MarkdownTheme.HANDLEBARS.helpers.relativeURL( + )}](${MarkdownTheme.HANDLEBARS.helpers.relativeURL( model.reflection.url, )})`, ] - : [emphasis ? `*${escape(model.name)}*` : escape(model.name)]; + : [emphasis ? `\`${escape(model.name)}\`` : escape(model.name)]; if (model.typeArguments && model.typeArguments.length > 0) { reflection.push( `<${model.typeArguments - .map((typeArgument) => `${type.call(typeArgument, 'none', false)}`) + .map((typeArgument) => `${type.call(typeArgument, 'all', false)}`) .join(', ')}\\>`, ); } return reflection.join(''); } - return escape(model.name); + return emphasis ? `\`${escape(model.name)}\`` : escape(model.name); } function getArrayType(model: ArrayType, emphasis: boolean) { @@ -232,7 +231,7 @@ function getTupleType(model: TupleType) { } function getIntrinsicType(model: IntrinsicType, emphasis: boolean) { - return emphasis ? `*${escape(model.name)}*` : escape(model.name); + return emphasis ? `\`${escape(model.name)}\`` : escape(model.name); } function getTypeOperatorType(model: TypeOperatorType) { @@ -240,7 +239,7 @@ function getTypeOperatorType(model: TypeOperatorType) { } function getQueryType(model: QueryType) { - return `*typeof* ${type.call(model.queryType)}`; + return `typeof ${type.call(model.queryType)}`; } function getTypeParameterType(model: TypeParameterType) { @@ -248,7 +247,7 @@ function getTypeParameterType(model: TypeParameterType) { } function getInferredType(model: InferredType) { - return `*infer* ${escape(model.name)}`; + return `infer ${escape(model.name)}`; } function getUnknownType(model: UnknownType) { @@ -260,7 +259,7 @@ function getConditionalType(model: ConditionalType) { if (model.checkType) { md.push(type.call(model.checkType)); } - md.push('*extends*'); + md.push('extends'); if (model.extendsType) { md.push(type.call(model.extendsType)); } diff --git a/packages/typedoc-plugin-markdown/src/resources/partials/member.declaration.hbs b/packages/typedoc-plugin-markdown/src/resources/partials/member.declaration.hbs index bd65686aa..ccdc00a0b 100755 --- a/packages/typedoc-plugin-markdown/src/resources/partials/member.declaration.hbs +++ b/packages/typedoc-plugin-markdown/src/resources/partials/member.declaration.hbs @@ -8,7 +8,7 @@ {{#with typeParameters}} -{{{parameterTable 'typeParameters'}}} +{{{typeParameterTable}}} {{/with}} @@ -16,10 +16,32 @@ {{#if type.declaration}} -#### Type declaration +{{#if type.declaration.indexSignature}} + +{{#with type.declaration.indexSignature}} + +#### Index signature + +{{{indexSignatureTitle}}} + +{{> comment}} + +{{/with}} + +{{/if}} {{#if type.declaration.signatures}} +{{#if type.declaration.children}} + +#### Call signature + +{{else}} + +#### Type declaration + +{{/if}} + {{#each type.declaration.signatures}} {{> member.signature showSources=false }} @@ -30,17 +52,15 @@ {{#if type.declaration.children}} -{{#if type.declaration}} - {{#with type.declaration}} -{{/with}} +#### Type declaration -{{/if}} +{{/with}} {{#with type.declaration.children}} -{{{propertyTable ../kind}}} +{{{propertyTable}}} {{/with}} diff --git a/packages/typedoc-plugin-markdown/src/resources/partials/member.signature.hbs b/packages/typedoc-plugin-markdown/src/resources/partials/member.signature.hbs index 3f71a4576..e4652c004 100644 --- a/packages/typedoc-plugin-markdown/src/resources/partials/member.signature.hbs +++ b/packages/typedoc-plugin-markdown/src/resources/partials/member.signature.hbs @@ -4,11 +4,19 @@ {{#if typeParameters}} +{{#if showSources}} + #### Type parameters +{{else}} + +##### Type parameters + +{{/if}} + {{#with typeParameters}} -{{{parameterTable 'typeParameters'}}} +{{{typeParameterTable}}} {{/with}} @@ -16,19 +24,43 @@ {{#if parameters}} +{{#if showSources}} + #### Parameters +{{else}} + +##### Parameters + +{{/if}} + {{#with parameters}} -{{{parameterTable 'parameters'}}} +{{{parameterTable}}} {{/with}} {{/if}} +{{#ifShowReturns}} + {{#if type}} -{{#with type}}{{{returns}}}{{/with}} +{{#if showSources}} + +#### Returns + +{{else}} + +##### Returns + +{{/if}} + +{{#with type}} + +{{{type 'all'}}} + +{{/with}} {{#if comment.returns}} @@ -40,8 +72,34 @@ {{/if}} +{{#with type}} + +{{#if declaration.signatures}} + +{{#each declaration.signatures}} + +{{> member.signature showSources=false }} + +{{/each}} + +{{/if}} + +{{#if declaration.children}} + +{{#with declaration.children}} + +{{{propertyTable}}} + +{{/with}} + +{{/if}} + +{{/with}} + {{/if}} +{{/ifShowReturns}} + {{#if showSources}} {{> member.sources}} diff --git a/packages/typedoc-plugin-markdown/src/resources/partials/member.sources.hbs b/packages/typedoc-plugin-markdown/src/resources/partials/member.sources.hbs index d1f3c831c..a999ee85c 100755 --- a/packages/typedoc-plugin-markdown/src/resources/partials/member.sources.hbs +++ b/packages/typedoc-plugin-markdown/src/resources/partials/member.sources.hbs @@ -1,32 +1,52 @@ {{#if implementationOf}} -Implementation of: {{#with implementationOf}}{{typeAndParent}}{{/with}} +#### Implementation of + +{{#with implementationOf}} + +{{typeAndParent}} + +{{/with}} {{/if}} {{#if inheritedFrom}} -Inherited from: {{#with inheritedFrom}}{{{typeAndParent}}}{{/with}} +#### Inherited from + +{{#with inheritedFrom}} + +{{{typeAndParent}}} + +{{/with}} {{/if}} {{#if overwrites}} -Overrides: {{#with overwrites}}{{typeAndParent}}{{/with}} +#### Overrides + +{{#with overwrites}} + +{{typeAndParent}} + +{{/with}} {{/if}} {{#if sources}} +#### Defined in + {{#each sources}} {{#if url}} -Defined in: [{{fileName}}:{{line}}]({{url}}) +[{{fileName}}:{{line}}]({{url}}) {{else}} -Defined in: {{fileName}}:{{line}} +{{fileName}}:{{line}} {{/if}} diff --git a/packages/typedoc-plugin-markdown/src/resources/templates/reflection.hbs b/packages/typedoc-plugin-markdown/src/resources/templates/reflection.hbs index 689e370d3..ce29bc542 100755 --- a/packages/typedoc-plugin-markdown/src/resources/templates/reflection.hbs +++ b/packages/typedoc-plugin-markdown/src/resources/templates/reflection.hbs @@ -18,7 +18,7 @@ {{#with model.typeParameters}} -{{{parameterTable 'typeParameters'}}} +{{{typeParameterTable}}} {{/with}} @@ -41,7 +41,7 @@ ## Implements {{#each model.implementedTypes}} -- {{{type false}}} +- {{{type}}} {{/each}} {{/if}} @@ -51,7 +51,7 @@ ## Implemented by {{#each model.implementedBy}} -- {{{type false}}} +- {{{type}}} {{/each}} {{/if}} @@ -64,6 +64,8 @@ {{#each signatures}} +### {{name}} + {{> member.signature showSources=true }} {{/each}} diff --git a/packages/typedoc-plugin-markdown/test/specs/__snapshots__/declarations.spec.ts.snap b/packages/typedoc-plugin-markdown/test/specs/__snapshots__/declarations.spec.ts.snap index 311b55e20..50e285102 100644 --- a/packages/typedoc-plugin-markdown/test/specs/__snapshots__/declarations.spec.ts.snap +++ b/packages/typedoc-plugin-markdown/test/specs/__snapshots__/declarations.spec.ts.snap @@ -1,141 +1,171 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Declarations: should compile a an udefined 1`] = ` -"• \`Let\` **undefinedNumberDeclaration**: *number* +exports[`Declarations: should compile a const with default value 1`] = ` +"• \`Const\` **stringConstWithDefaultValue**: \`\`\\"hello\\"\`\` [partial: member.sources] " `; -exports[`Declarations: should compile a variable with default value 1`] = ` -"• \`Const\` **stringWithDefaultValueDeclaration**: \`\`\\"variable\\"\`\`= 'variable' +exports[`Declarations: should compile a let with default value 1`] = ` +"• \`Let\` **stringLetWithDefaultValue**: \`string\` = 'hello' + +[partial: member.sources] +" +`; + +exports[`Declarations: should compile an undefined declaration 1`] = ` +"• \`Let\` **undefinedNumberDeclaration**: \`number\` [partial: member.sources] " `; exports[`Declarations: should compile any function type 1`] = ` -"Ƭ **AnyFunctionType**: (...\`input\`: *any*[]) => A +"Ƭ **AnyFunctionType**: (...\`input\`: \`any\`[]) => \`A\` #### Type parameters -| Name | Default | +| Name | Type | | :------ | :------ | -| \`A\` | *any* | +| \`A\` | \`A\` = \`any\` | #### Type declaration -▸ (...\`input\`: *any*[]): A +▸ (...\`input\`): \`A\` -#### Parameters +##### Parameters | Name | Type | | :------ | :------ | -| \`...input\` | *any*[] | +| \`...input\` | \`any\`[] | -**Returns:** A +##### Returns + +\`A\` [partial: member.sources] " `; -exports[`Declarations: should compile declaration with double underscores in name and value 1`] = ` -"• \`Const\` **\\\\_\\\\_DOUBLE\\\\_UNDERSCORES\\\\_DECLARATION\\\\_\\\\_**: *typeof* [*\\\\_\\\\_DOUBLE\\\\_UNDERSCORES\\\\_DECLARATION\\\\_\\\\_*](../modules.md#__double_underscores_declaration__) +exports[`Declarations: should compile callable declaration 1`] = ` +"• \`Let\` **callableDeclaration**: \`Object\` + +#### Call signature + +▸ (\`someArg\`): \`boolean\` + +##### Parameters + +| Name | Type | +| :------ | :------ | +| \`someArg\` | \`number\` | + +##### Returns + +\`boolean\` + +#### Type declaration + +| Name | Type | +| :------ | :------ | +| \`arg1\` | \`string\` | +| \`arg2\` | \`number\` | [partial: member.sources] " `; -exports[`Declarations: should compile enum delcaration 1`] = ` -"• **Down**: = \\"DOWN\\" +exports[`Declarations: should compile declaration with double underscores in name and value 1`] = ` +"• \`Const\` **\\\\_\\\\_DOUBLE\\\\_UNDERSCORES\\\\_DECLARATION\\\\_\\\\_**: typeof [\\\\_\\\\_DOUBLE\\\\_UNDERSCORES\\\\_DECLARATION\\\\_\\\\_](../modules.md#__double_underscores_declaration__) [partial: member.sources] " `; -exports[`Declarations: should compile object literal cast as a const 1`] = ` -"• \`Const\` **objectLiteralAsConstDeclaration**: *object* - -Comments +exports[`Declarations: should compile enum delcaration 1`] = ` +"• **Down** = \\"DOWN\\" -#### Type declaration +[partial: member.sources] +" +`; -| Name | Type | Description | -| :------ | :------ | :------ | -| \`Prop1\` | \`\`\\"Prop1\\"\`\` | Comment for Prop1. | -| \`Prop2\` | \`\`\\"Prop2\\"\`\` | Comment for Prop2. | -| \`Prop3\` | \`\`\\"Prop3\\"\`\` | - | +exports[`Declarations: should compile function declaration 1`] = ` +"• \`Let\` **functionDeclaration**: (\`someArg\`: \`number\`) => \`boolean\` [partial: member.sources] " `; -exports[`Declarations: should compile object literal declaration 1`] = ` -"• \`Const\` **objectLiteralDeclaration**: *object* +exports[`Declarations: should compile indexable declaration 1`] = ` +"• \`Let\` **indexableDeclaration**: \`Object\` + +#### Index signature + +▪ [index: \`number\`]: \`string\` #### Type declaration -| Name | Type | Description | -| :------ | :------ | :------ | -| \`valueA\` | *number* | - | -| \`valueB\` | *boolean* | - | -| \`valueC\` | *object* | - | -| \`valueX\` | *object* | - | -| \`valueX.valueA\` | *number*[] | description for valuea | -| \`valueX.valueZ\` | *string* | - | -| \`valueY\` | () => *string* | - | -| \`valueZ\` | *string* | description for valuez | +| Name | Type | +| :------ | :------ | +| \`arg1\` | \`string\` | [partial: member.sources] " `; -exports[`Declarations: should compile type literal declaration 1`] = ` -"• \`Let\` **typeLiteralDeclaration**: *object* +exports[`Declarations: should compile object literal cast as a const 1`] = ` +"• \`Const\` **objectLiteralAsConstDeclaration**: \`Object\` + +Comments #### Type declaration | Name | Type | Description | | :------ | :------ | :------ | -| \`valueA?\` | *number* | Comments for valueA | -| \`valueB?\` | *boolean* | - | -| \`valueX\` | *object* | Comment for valueX | -| \`valueX.valueA\` | *number*[] | - | -| \`valueX.valueY\` | (\`z\`: *string*) => { \`a\`: *string* ; \`b\`: *string* } | - | -| \`valueX.valueZ\` | *string* | Nested comment for valueZ | -| \`valueY\` | () => *string* | - | -| \`valueZ\` | *string* | Comment for valueZ | +| \`Prop1\` | \`\`\\"Prop1\\"\`\` | Comment for Prop1. | +| \`Prop2\` | \`\`\\"Prop2\\"\`\` | Comment for Prop2. | +| \`Prop3\` | \`\`\\"Prop3\\"\`\` | - | [partial: member.sources] " `; -exports[`Declarations: should compile type literal declaration 2`] = ` -"• \`Let\` **typeLiteralDeclarationWithFunction**: () => *string* +exports[`Declarations: should compile object literal declaration 1`] = ` +"• \`Const\` **objectLiteralDeclaration**: \`Object\` #### Type declaration -▸ (): *string* - -**Returns:** *string* - -| Name | Type | -| :------ | :------ | -| \`valueZ\` | *string* | +| Name | Type | Description | +| :------ | :------ | :------ | +| \`valueA\` | \`number\` | - | +| \`valueB\` | \`boolean\` | - | +| \`valueC\` | \`Object\` | - | +| \`valueX\` | \`Object\` | description for valueX | +| \`valueX.valueA\` | \`number\`[] | - | +| \`valueX.valueZ\` | \`string\` | - | +| \`valueY\` | () => \`string\` | description for valueY | +| \`valueZ\` | \`string\` | description for valueZ | [partial: member.sources] " `; -exports[`Declarations: should not escape charcters within markdown code 1`] = ` -"Ƭ **SpecialCharacters**: *object* +exports[`Declarations: should compile type literal declaration 1`] = ` +"• \`Let\` **typeLiteralDeclaration**: \`Object\` #### Type declaration -| Name | Type | -| :------ | :------ | -| \`this_prop_has_underscores\` | *number* | -| this\\\\|prop\\\\|has\\\\|the\\\\|pipe\\\\|character | *string* | +| Name | Type | Description | +| :------ | :------ | :------ | +| \`valueA?\` | \`number\` | Comments for valueA | +| \`valueB?\` | \`boolean\` | - | +| \`valueX\` | \`Object\` | Comment for valueX | +| \`valueX.valueA\` | \`number\`[] | - | +| \`valueX.valueY\` | (\`z\`: \`string\`) => { \`a\`: \`string\` ; \`b\`: \`string\` } | - | +| \`valueX.valueZ\` | \`string\` | Nested comment for valueZ | +| \`valueY\` | () => \`string\` | - | +| \`valueZ\` | \`string\` | Comment for valueZ | [partial: member.sources] " diff --git a/packages/typedoc-plugin-markdown/test/specs/__snapshots__/generics.spec.ts.snap b/packages/typedoc-plugin-markdown/test/specs/__snapshots__/generics.spec.ts.snap new file mode 100644 index 000000000..6567c169f --- /dev/null +++ b/packages/typedoc-plugin-markdown/test/specs/__snapshots__/generics.spec.ts.snap @@ -0,0 +1,57 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Generics: should compile class with type params 1`] = ` +"[helper: breadcrumbs] + +# Class: ClassWithTypeParams + +[partial: comment] + +## Type parameters + +| Name | Description | +| :------ | :------ | +| \`T\` | Some type param | +| \`V\` | Some other type param | + +[helper: toc] + +[partial: members] +" +`; + +exports[`Generics: should compile function with a simple type param' 1`] = ` +"▸ \`Const\` **functionWithTypeParam**(): \`boolean\` + +[partial: comment] + +##### Type parameters + +| Name | +| :------ | +| \`A\` | + +##### Returns + +\`boolean\` +" +`; + +exports[`Generics: should compile function with complex type params' 1`] = ` +"▸ \`Const\` **functionWithTypeParams**(): \`boolean\` + +[partial: comment] + +##### Type parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| \`A\` | \`A\`: [ClassWithTypeParams](classwithtypeparams.md) | Comment for type \`A\` | +| \`B\` | \`B\` = \`string\` \\\\| \`boolean\` | Comment for type \`B\` | +| \`C\` | \`C\` = \`string\` | - | + +##### Returns + +\`boolean\` +" +`; diff --git a/packages/typedoc-plugin-markdown/test/specs/__snapshots__/hierarchy.spec.ts.snap b/packages/typedoc-plugin-markdown/test/specs/__snapshots__/hierarchy.spec.ts.snap index 014848ec5..90b58c7f5 100644 --- a/packages/typedoc-plugin-markdown/test/specs/__snapshots__/hierarchy.spec.ts.snap +++ b/packages/typedoc-plugin-markdown/test/specs/__snapshots__/hierarchy.spec.ts.snap @@ -1,19 +1,19 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`Hierarchy: should compile nested type hierarchy 1`] = ` -"- [*ParentClass*](parentclass.md) +"- [ParentClass](parentclass.md) ↳ **ChildClassA** - ↳↳ [*GrandChildClassA*](grandchildclassa.md) + ↳↳ [GrandChildClassA](grandchildclassa.md) " `; exports[`Hierarchy: should compile type hierarchy 1`] = ` "- **ParentClass** - ↳ [*ChildClassA*](childclassa.md) + ↳ [ChildClassA](childclassa.md) - ↳ [*ChildClassB*](childclassb.md) + ↳ [ChildClassB](childclassb.md) " `; diff --git a/packages/typedoc-plugin-markdown/test/specs/__snapshots__/members.spec.ts.snap b/packages/typedoc-plugin-markdown/test/specs/__snapshots__/members.spec.ts.snap index 5aa35a789..4886dd991 100644 --- a/packages/typedoc-plugin-markdown/test/specs/__snapshots__/members.spec.ts.snap +++ b/packages/typedoc-plugin-markdown/test/specs/__snapshots__/members.spec.ts.snap @@ -3,9 +3,11 @@ exports[`Members: (member) should compile a signature members' 1`] = ` "### signatureMember -▸ **signatureMember**(): *void* +▸ **signatureMember**(): \`void\` -**Returns:** *void* +#### Returns + +\`void\` [partial: member.sources] @@ -16,7 +18,7 @@ ___ exports[`Members: (member) should compile declaration members' 1`] = ` "### declarationMember -• \`Let\` **declarationMember**: *string* +• \`Let\` **declarationMember**: \`string\` [partial: member.sources] @@ -27,9 +29,11 @@ ___ exports[`Members: (member) should compile members with getter' 1`] = ` "### getter -• get **getter**(): *string* +• \`get\` **getter**(): \`string\` + +#### Returns -**Returns:** *string* +\`string\` [partial: member.sources] @@ -40,15 +44,17 @@ ___ exports[`Members: (member) should compile members with setter' 1`] = ` "### setter -• set **setter**(\`value\`: *string*): *void* +• \`set\` **setter**(\`value\`): \`void\` #### Parameters | Name | Type | | :------ | :------ | -| \`value\` | *string* | +| \`value\` | \`string\` | + +#### Returns -**Returns:** *void* +\`void\` [partial: member.sources] diff --git a/packages/typedoc-plugin-markdown/test/specs/__snapshots__/reflections.spec.ts.snap b/packages/typedoc-plugin-markdown/test/specs/__snapshots__/reflections.spec.ts.snap index dca792eef..8ab2809e9 100644 --- a/packages/typedoc-plugin-markdown/test/specs/__snapshots__/reflections.spec.ts.snap +++ b/packages/typedoc-plugin-markdown/test/specs/__snapshots__/reflections.spec.ts.snap @@ -9,11 +9,22 @@ exports[`Reflections: (header) should compile template with breadcrumbs and with " `; +exports[`Reflections: (template) should compile Enum 1`] = ` +"# Enumeration: EnumReflection + +[helper: toc] + +[partial: members] +" +`; + exports[`Reflections: (template) should compile a callable reflection 1`] = ` "# Interface: CallableReflection ## Callable +### CallableReflection + [partial: member.signature] [helper: toc] @@ -27,7 +38,7 @@ exports[`Reflections: (template) should compile an indexable reflection 1`] = ` ## Indexable -▪ [index: *number*]: *string* +▪ [index: \`number\`]: \`string\` [partial: comment] @@ -42,7 +53,7 @@ exports[`Reflections: (template) should compile implemented class 1`] = ` ## Implements -- [*ReflectionClass*](../classes/reflectionclass.md) +- [ReflectionClass](../classes/reflectionclass.md) [helper: toc] @@ -58,21 +69,3 @@ exports[`Reflections: (template) should compile module with breadcrumbs and proj [partial: members] " `; - -exports[`Reflections: (template) should compile reflection with type params 1`] = ` -"# Interface: ReflectionWithTypeParams - -[partial: comment] - -## Type parameters - -| Name | Description | -| :------ | :------ | -| \`T\` | Some type param | -| \`V\` | Some other type param | - -[helper: toc] - -[partial: members] -" -`; diff --git a/packages/typedoc-plugin-markdown/test/specs/__snapshots__/signatures.spec.ts.snap b/packages/typedoc-plugin-markdown/test/specs/__snapshots__/signatures.spec.ts.snap index cf24089cc..aa4e0c1f0 100644 --- a/packages/typedoc-plugin-markdown/test/specs/__snapshots__/signatures.spec.ts.snap +++ b/packages/typedoc-plugin-markdown/test/specs/__snapshots__/signatures.spec.ts.snap @@ -1,220 +1,275 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`Signatures: should compile callable signature' 1`] = ` -"▸ **CallableSignature**(): *string* +"▸ **CallableSignature**(): \`string\` -**Returns:** *string* +##### Returns + +\`string\` +" +`; + +exports[`Signatures: should compile class with constructor' 1`] = ` +"• **new ClassWithConstructor**(\`x\`, \`y\`) + +##### Parameters + +| Name | Type | +| :------ | :------ | +| \`x\` | \`string\` | +| \`y\` | \`string\` | " `; exports[`Signatures: should compile function that returns a function' 1`] = ` -"▸ **functionReturningAFunction**(): *function* +"▸ **functionReturningAFunction**(): (\`x\`: \`string\`) => \`boolean\` + +Comments for function -**Returns:** () => *boolean* +##### Returns + +\`fn\` + +Return comments + +▸ (\`x\`): \`boolean\` + +##### Type parameters + +| Name | +| :------ | +| \`T\` | + +##### Parameters + +| Name | Type | +| :------ | :------ | +| \`x\` | \`string\` | + +##### Returns + +\`boolean\` " `; exports[`Signatures: should compile function that returns an object' 1`] = ` -"▸ **functionReturningAnObject**(): *object* +"▸ **functionReturningAnObject**(): \`Object\` + +Comments for function + +##### Returns -**Returns:** *object* +\`Object\` + +Return comments | Name | Type | | :------ | :------ | -| \`x\` | *number* | -| \`y\` | *number* | +| \`x\` | \`number\` | +| \`y\` | \`number\` | " `; exports[`Signatures: should compile function with nested typen params' 1`] = ` -"▸ **functionWithNestedParams**(\`params\`: { \`name\`: *string* ; \`nestedObj\`: { \`name\`: *string* ; \`obj\`: { \`name\`: () => *void* } ; \`value\`: *number* } ; \`parent?\`: *number* }, \`context\`: *any*): *boolean* +"▸ **functionWithNestedParams**(\`params\`, \`context\`): \`boolean\` Some nested params. -#### Parameters +##### Parameters | Name | Type | Description | | :------ | :------ | :------ | -| \`params\` | *object* | The parameters passed to the method. | -| \`params.name\` | *string* | The name of the new group. | -| \`params.nestedObj\` | *object* | A nested object. | -| \`params.nestedObj.name\` | *string* | - | -| \`params.nestedObj.obj\` | *object* | - | -| \`params.nestedObj.obj.name\` | () => *void* | - | -| \`params.nestedObj.value\` | *number* | - | -| \`params.parent?\` | *number* | - | -| \`context\` | *any* | The context of the method call. | - -**Returns:** *boolean* +| \`params\` | \`Object\` | The parameters passed to the method. | +| \`params.name\` | \`string\` | The name of the new group. | +| \`params.nestedObj\` | \`Object\` | A nested object. | +| \`params.nestedObj.name\` | \`string\` | - | +| \`params.nestedObj.obj\` | \`Object\` | - | +| \`params.nestedObj.obj.name\` | () => \`void\` | - | +| \`params.nestedObj.value\` | \`number\` | - | +| \`params.parent?\` | \`number\` | - | +| \`context\` | \`any\` | The context of the method call. | + +##### Returns + +\`boolean\` " `; exports[`Signatures: should compile function with reference type' 1`] = ` -"▸ **functionWithReferenceType**(\`descriptor\`: *TypedPropertyDescriptor*): *boolean* +"▸ **functionWithReferenceType**(\`descriptor\`): \`boolean\` -#### Parameters +##### Parameters | Name | Type | | :------ | :------ | -| \`descriptor\` | *TypedPropertyDescriptor* | +| \`descriptor\` | \`TypedPropertyDescriptor\` | -**Returns:** *boolean* +##### Returns + +\`boolean\` " `; exports[`Signatures: should compile named parameters with comments' 1`] = ` -"▸ **functionWithNamedParamsAndComments**(\`__namedParameters?\`: { \`bar?\`: *number* ; \`foo?\`: *number* }, \`anotherParam\`: *string*): *void* +"▸ **functionWithNamedParamsAndComments**(\`__namedParameters?\`, \`anotherParam\`): \`void\` FOO -#### Parameters +##### Parameters -| Name | Type | Default value | Description | -| :------ | :------ | :------ | :------ | -| \`__namedParameters\` | *object* | {} | various options | -| \`__namedParameters.bar?\` | *number* | - | Another value | -| \`__namedParameters.foo?\` | *number* | - | An interesting value | -| \`anotherParam\` | *string* | - | - | +| Name | Type | Description | +| :------ | :------ | :------ | +| \`__namedParameters\` | \`Object\` | various options | +| \`__namedParameters.bar?\` | \`number\` | Another value | +| \`__namedParameters.foo?\` | \`number\` | An interesting value | +| \`anotherParam\` | \`string\` | - | + +##### Returns -**Returns:** *void* +\`void\` " `; exports[`Signatures: should compile named parameters' 1`] = ` -"▸ **functionWithNamedParams**(\`__namedParameters\`: *Object*): *string* +"▸ **functionWithNamedParams**(\`__namedParameters\`): \`string\` -#### Parameters +##### Parameters | Name | Type | | :------ | :------ | -| \`__namedParameters\` | *Object* | +| \`__namedParameters\` | \`Object\` | -**Returns:** *string* +##### Returns + +\`string\` " `; exports[`Signatures: should compile pipes in params and comments' 1`] = ` -"▸ **functionWithPipesInParamsAndComments**(\`n\`: *number* \\\\| \`\`null\`\`): *number* \\\\| \`\`null\`\` +"▸ **functionWithPipesInParamsAndComments**(\`n\`): \`number\` \\\\| \`\`null\`\` -#### Parameters +##### Parameters | Name | Type | Description | | :------ | :------ | :------ | -| \`n\` | *number* \\\\| \`\`null\`\` | a\\\\|b | +| \`n\` | \`number\` \\\\| \`\`null\`\` | a\\\\|b | + +##### Returns -**Returns:** *number* \\\\| \`\`null\`\` +\`number\` \\\\| \`\`null\`\` " `; exports[`Signatures: should compile signature with @return comments' 1`] = ` -"▸ **commentsInReturn**(): *boolean* +"▸ **commentsInReturn**(): \`boolean\` Comments with a return definition -**Returns:** *boolean* +##### Returns + +\`boolean\` Return comments " `; exports[`Signatures: should compile signature with a flag' 1`] = ` -"▸ \`Private\` **privateFunction**(): *string* +"▸ \`Private\` **privateFunction**(): \`string\` -**Returns:** *string* +##### Returns + +\`string\` " `; exports[`Signatures: should compile signature with default values' 1`] = ` -"▸ **functionWithDefaults**(\`valueA?\`: *string*, \`valueB?\`: *number*, \`valueC?\`: *number*, \`valueD?\`: *boolean*, \`valueE?\`: *boolean*, \`valueF?\`: *string*): *string* +"▸ **functionWithDefaults**(\`valueA?\`, \`valueB?\`, \`valueC?\`, \`valueD?\`, \`valueE?\`, \`valueF?\`): \`string\` This is a function with a parameter that has a default value. -#### Parameters +##### Parameters | Name | Type | Default value | Description | | :------ | :------ | :------ | :------ | -| \`valueA\` | *string* | 'defaultValue' | A parameter with a default string value. | -| \`valueB\` | *number* | 100 | A parameter with a default numeric value. | -| \`valueC\` | *number* | - | A parameter with a default NaN value. | -| \`valueD\` | *boolean* | true | A parameter with a default boolean value. | -| \`valueE\` | *boolean* | null | A parameter with a default null value. | -| \`valueF\` | *string* | '' | - | +| \`valueA\` | \`string\` | 'defaultValue' | A parameter with a default string value. | +| \`valueB\` | \`number\` | 100 | A parameter with a default numeric value. | +| \`valueC\` | \`number\` | \`undefined\` | A parameter with a default NaN value. | +| \`valueD\` | \`boolean\` | true | A parameter with a default boolean value. | +| \`valueE\` | \`boolean\` | null | A parameter with a default null value. | +| \`valueF\` | \`string\` | '' | - | + +##### Returns -**Returns:** *string* +\`string\` " `; exports[`Signatures: should compile signature with optional params' 1`] = ` -"▸ **functionWithOptionalParam**(\`requiredParam\`: *string*, \`optionalParam?\`: *string*): *void* +"▸ **functionWithOptionalParam**(\`requiredParam\`, \`optionalParam?\`): \`void\` This is a function with a parameter that is optional. -#### Parameters +##### Parameters | Name | Type | Description | | :------ | :------ | :------ | -| \`requiredParam\` | *string* | A normal parameter. | -| \`optionalParam?\` | *string* | An optional parameter. | +| \`requiredParam\` | \`string\` | A normal parameter. | +| \`optionalParam?\` | \`string\` | An optional parameter. | + +##### Returns -**Returns:** *void* +\`void\` " `; exports[`Signatures: should compile signature with params' 1`] = ` -"▸ **functionWithParameters**(\`paramZ\`: *string*, \`paramG\`: *any*, \`paramA\`: *any*): *number* +"▸ **functionWithParameters**(\`paramZ\`, \`paramG\`, \`paramA\`): \`number\` This is a function with multiple arguments and a return value. -#### Parameters +##### Parameters | Name | Type | Description | | :------ | :------ | :------ | -| \`paramZ\` | *string* | This is a string parameter. | -| \`paramG\` | *any* | This is a parameter flagged with any.
This sentence is placed in the next line. | -| \`paramA\` | *any* | This is a **parameter** pointing to an interface. | +| \`paramZ\` | \`string\` | This is a string parameter. | +| \`paramG\` | \`any\` | This is a parameter flagged with any.
This sentence is placed in the next line. | +| \`paramA\` | \`any\` | This is a **parameter** pointing to an interface. | -**Returns:** *number* +##### Returns + +\`number\` " `; exports[`Signatures: should compile signature with rest params' 1`] = ` -"▸ **functionWithRest**(...\`rest\`: *string*[]): *string* +"▸ **functionWithRest**(...\`rest\`): \`string\` This is a function with rest parameter. -#### Parameters +##### Parameters | Name | Type | Description | | :------ | :------ | :------ | -| \`...rest\` | *string*[] | The rest parameter. | +| \`...rest\` | \`string\`[] | The rest parameter. | -**Returns:** *string* -" -`; +##### Returns -exports[`Signatures: should compile signature with type params' 1`] = ` -"▸ \`Const\` **functionWithTypeParams**(): *boolean* - -#### Type parameters - -| Name | Default | -| :------ | :------ | -| \`Item\` | *string* \\\\| *boolean* | - -**Returns:** *boolean* +\`string\` " `; exports[`Signatures: should compile signature with union types' 1`] = ` -"▸ **functionWithUnionTypes**(\`arg\`: *boolean*[] \\\\| *number*, ...\`args\`: (*string* \\\\| *number*)[]): *any* +"▸ **functionWithUnionTypes**(\`arg\`, ...\`args\`): \`any\` -#### Parameters +##### Parameters | Name | Type | | :------ | :------ | -| \`arg\` | *boolean*[] \\\\| *number* | -| \`...args\` | (*string* \\\\| *number*)[] | +| \`arg\` | \`boolean\`[] \\\\| \`number\` | +| \`...args\` | (\`string\` \\\\| \`number\`)[] | + +##### Returns -**Returns:** *any* +\`any\` " `; diff --git a/packages/typedoc-plugin-markdown/test/specs/__snapshots__/sources.spec.ts.snap b/packages/typedoc-plugin-markdown/test/specs/__snapshots__/sources.spec.ts.snap index c0134fd7d..e08f307a9 100644 --- a/packages/typedoc-plugin-markdown/test/specs/__snapshots__/sources.spec.ts.snap +++ b/packages/typedoc-plugin-markdown/test/specs/__snapshots__/sources.spec.ts.snap @@ -1,15 +1,34 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`Sources: should display implementation of sources' 1`] = ` -"Implementation of: [SomeInterface](someinterface.md).[prop](someinterface.md#prop) +"#### Implementation of -Defined in: sources.ts:6 +[SomeInterface](someinterface.md).[prop](someinterface.md#prop) + +#### Defined in + +sources.ts:6 +" +`; + +exports[`Sources: should display inherited sources' 1`] = ` +"#### Inherited from + +[SomeClass](../classes/someclass.md).[prop](../classes/someclass.md#prop) + +#### Defined in + +sources.ts:2 " `; -exports[`Sources: should display inherited and overide sources' 1`] = ` -"Inherited from: [SomeClass](../classes/someclass.md).[prop](../classes/someclass.md#prop) +exports[`Sources: should display overide sources' 1`] = ` +"#### Overrides + +[SomeClass](../classes/someclass.md).[prop](../classes/someclass.md#prop) + +#### Defined in -Defined in: sources.ts:2 +sources.ts:10 " `; diff --git a/packages/typedoc-plugin-markdown/test/specs/__snapshots__/types.spec.ts.snap b/packages/typedoc-plugin-markdown/test/specs/__snapshots__/types.spec.ts.snap index b7a415cc7..23c0f9d55 100644 --- a/packages/typedoc-plugin-markdown/test/specs/__snapshots__/types.spec.ts.snap +++ b/packages/typedoc-plugin-markdown/test/specs/__snapshots__/types.spec.ts.snap @@ -1,20 +1,20 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`Types: should compile 'array' type' 1`] = ` -"*string*[] +"\`string\`[] " `; -exports[`Types: should compile 'intersection' type' 1`] = `"[*IntersectionClassA*](intersectionclassa.md) & [*IntersectionClassB*](intersectionclassb.md)"`; +exports[`Types: should compile 'intersection' type' 1`] = `"[IntersectionClassA](intersectionclassa.md) & [IntersectionClassB](intersectionclassb.md)"`; exports[`Types: should compile 'stringLiteral' type' 1`] = ` "\`\`\\"blue\\"\`\` " `; -exports[`Types: should compile 'tuple' type' 1`] = `"[*string*, *number*]"`; +exports[`Types: should compile 'tuple' type' 1`] = `"[\`string\`, \`number\`]"`; -exports[`Types: should compile 'typeOperator' type ' 1`] = `"unique *symbol*"`; +exports[`Types: should compile 'typeOperator' type ' 1`] = `"unique \`symbol\`"`; exports[`Types: should compile 'union' of literal declarations 1`] = ` "{ \`bar\`: \`\`\\" \\"\`\` \\\\| \`\`\\"string\\"\`\` \\\\| \`\`\\"strong|with|pipes\\"\`\` \\\\| \`\`\\"type\`with\`backticks\\"\`\` \\\\| \`\`\\"*\\"\`\` } @@ -28,18 +28,18 @@ exports[`Types: should compile 'union' of string literals types' 1`] = ` exports[`Types: should compile collapsed 'function' type ' 1`] = `""`; -exports[`Types: should compile collapsed 'literal' type' 1`] = `"*object*"`; +exports[`Types: should compile collapsed 'literal' type' 1`] = `"\`Object\`"`; -exports[`Types: should compile collapsed 'objectLiteralType' type' 1`] = `"*object*"`; +exports[`Types: should compile collapsed 'objectLiteralType' type' 1`] = `"\`Object\`"`; -exports[`Types: should compile conditional type ' 1`] = `"T *extends* *string* ? \`\`\\"string\\"\`\` : T *extends* *number* ? \`\`\\"number\\"\`\` : T *extends* *boolean* ? \`\`\\"boolean\\"\`\` : T *extends* *undefined* ? \`\`\\"undefined\\"\`\` : \`\`\\"object\\"\`\`"`; +exports[`Types: should compile conditional type ' 1`] = `"\`T\` extends \`string\` ? \`\`\\"string\\"\`\` : \`T\` extends \`number\` ? \`\`\\"number\\"\`\` : \`T\` extends \`boolean\` ? \`\`\\"boolean\\"\`\` : \`T\` extends \`undefined\` ? \`\`\\"undefined\\"\`\` : \`\`\\"object\\"\`\`"`; exports[`Types: should compile expanded 'function' type ' 1`] = `""`; -exports[`Types: should compile expanded 'literal' type' 1`] = `"{ \`valueA?\`: *number* ; \`valueB?\`: *boolean* ; \`valueX\`: { \`valueA\`: *number*[] ; \`valueY\`: (\`z\`: *string*) => { \`a\`: *string* ; \`b\`: *string* } ; \`valueZ\`: *string* } ; \`valueY\`: () => *string* ; \`valueZ\`: *string* }"`; +exports[`Types: should compile expanded 'literal' type' 1`] = `"{ \`valueA?\`: \`number\` ; \`valueB?\`: \`boolean\` ; \`valueX\`: { \`valueA\`: \`number\`[] ; \`valueY\`: (\`z\`: \`string\`) => { \`a\`: \`string\` ; \`b\`: \`string\` } ; \`valueZ\`: \`string\` } ; \`valueY\`: () => \`string\` ; \`valueZ\`: \`string\` }"`; exports[`Types: should compile expanded 'objectLiteralType' type' 1`] = `"{}"`; -exports[`Types: should compile intrinsic type' 1`] = `"*string*"`; +exports[`Types: should compile intrinsic type' 1`] = `"\`string\`"`; -exports[`Types: should compile unionType with object literal type ' 1`] = `"*string* \\\\| { \`z\`: *string* }"`; +exports[`Types: should compile unionType with object literal type ' 1`] = `"\`string\` \\\\| { \`z\`: \`string\` }"`; diff --git a/packages/typedoc-plugin-markdown/test/specs/declarations.spec.ts b/packages/typedoc-plugin-markdown/test/specs/declarations.spec.ts index e5ee38050..c02f200ce 100644 --- a/packages/typedoc-plugin-markdown/test/specs/declarations.spec.ts +++ b/packages/typedoc-plugin-markdown/test/specs/declarations.spec.ts @@ -11,21 +11,28 @@ describe(`Declarations:`, () => { testApp = new TestApp(['declarations.ts']); await testApp.bootstrap(); TestApp.stubPartials(['member.sources']); - TestApp.stubHelpers([]); - template = TestApp.getPartial('member.declaration'); }); - test(`should compile a variable with default value`, () => { + test(`should compile a const with default value`, () => { + expect( + TestApp.compileTemplate( + template, + testApp.findReflection('stringConstWithDefaultValue'), + ), + ).toMatchSnapshot(); + }); + + test(`should compile a let with default value`, () => { expect( TestApp.compileTemplate( template, - testApp.findReflection('stringWithDefaultValueDeclaration'), + testApp.findReflection('stringLetWithDefaultValue'), ), ).toMatchSnapshot(); }); - test(`should compile a an udefined`, () => { + test(`should compile an undefined declaration`, () => { expect( TestApp.compileTemplate( template, @@ -61,38 +68,47 @@ describe(`Declarations:`, () => { ).toMatchSnapshot(); }); - test(`should compile type literal declaration`, () => { + test(`should compile declaration with double underscores in name and value`, () => { expect( TestApp.compileTemplate( template, - testApp.findReflection('typeLiteralDeclarationWithFunction'), + testApp.findReflection('__DOUBLE_UNDERSCORES_DECLARATION__'), ), ).toMatchSnapshot(); }); - test(`should compile declaration with double underscores in name and value`, () => { + test(`should compile any function type`, () => { expect( TestApp.compileTemplate( template, - testApp.findReflection('__DOUBLE_UNDERSCORES_DECLARATION__'), + testApp.findReflection('AnyFunctionType'), ), ).toMatchSnapshot(); }); - test(`should compile any function type`, () => { + test(`should compile function declaration`, () => { expect( TestApp.compileTemplate( template, - testApp.findReflection('AnyFunctionType'), + testApp.findReflection('functionDeclaration'), + ), + ).toMatchSnapshot(); + }); + + test(`should compile callable declaration`, () => { + expect( + TestApp.compileTemplate( + template, + testApp.findReflection('callableDeclaration'), ), ).toMatchSnapshot(); }); - test(`should not escape charcters within markdown code`, () => { + test(`should compile indexable declaration`, () => { expect( TestApp.compileTemplate( template, - testApp.findReflection('SpecialCharacters'), + testApp.findReflection('indexableDeclaration'), ), ).toMatchSnapshot(); }); diff --git a/packages/typedoc-plugin-markdown/test/specs/generics.spec.ts b/packages/typedoc-plugin-markdown/test/specs/generics.spec.ts new file mode 100644 index 000000000..bc9405b7f --- /dev/null +++ b/packages/typedoc-plugin-markdown/test/specs/generics.spec.ts @@ -0,0 +1,51 @@ +import * as Handlebars from 'handlebars'; +import { SignatureReflection } from 'typedoc'; + +import { TestApp } from '../test-app'; + +describe(`Generics:`, () => { + let testApp: TestApp; + let partial: Handlebars.TemplateDelegate; + let reflectionTemplate: Handlebars.TemplateDelegate; + + beforeAll(() => { + testApp = new TestApp(['generics.ts']); + partial = TestApp.getPartial('member.signature'); + }); + + beforeEach(async () => { + await testApp.bootstrap(); + TestApp.stubPartials(['comment', 'member.signature', 'members']); + TestApp.stubHelpers(['toc', 'breadcrumbs', 'hierarchy', 'returns']); + reflectionTemplate = TestApp.getTemplate('reflection'); + }); + + test(`should compile class with type params`, () => { + expect( + TestApp.compileTemplate(reflectionTemplate, { + model: testApp.findReflection('ClassWithTypeParams'), + project: testApp.project, + }), + ).toMatchSnapshot(); + }); + + test(`should compile function with a simple type param'`, () => { + expect( + TestApp.compileTemplate( + partial, + testApp.findReflection('functionWithTypeParam') + .signatures[0] as SignatureReflection, + ), + ).toMatchSnapshot(); + }); + + test(`should compile function with complex type params'`, () => { + expect( + TestApp.compileTemplate( + partial, + testApp.findReflection('functionWithTypeParams') + .signatures[0] as SignatureReflection, + ), + ).toMatchSnapshot(); + }); +}); diff --git a/packages/typedoc-plugin-markdown/test/specs/reflections.spec.ts b/packages/typedoc-plugin-markdown/test/specs/reflections.spec.ts index fc463fdde..cce431f27 100644 --- a/packages/typedoc-plugin-markdown/test/specs/reflections.spec.ts +++ b/packages/typedoc-plugin-markdown/test/specs/reflections.spec.ts @@ -50,37 +50,37 @@ describe(`Reflections:`, () => { ).toMatchSnapshot(); }); - test(`should compile reflection with type params`, () => { + test(`should compile a callable reflection`, () => { expect( TestApp.compileTemplate(reflectionTemplate, { - model: testApp.findReflection('ReflectionWithTypeParams'), + model: testApp.findReflection('CallableReflection'), project: testApp.project, }), ).toMatchSnapshot(); }); - test(`should compile a callable reflection`, () => { + test(`should compile an indexable reflection`, () => { expect( TestApp.compileTemplate(reflectionTemplate, { - model: testApp.findReflection('CallableReflection'), + model: testApp.findReflection('IndexableReflection'), project: testApp.project, }), ).toMatchSnapshot(); }); - test(`should compile an indexable reflection`, () => { + test(`should compile implemented class`, () => { expect( TestApp.compileTemplate(reflectionTemplate, { - model: testApp.findReflection('IndexableReflection'), + model: testApp.findReflection('ImplementedClass'), project: testApp.project, }), ).toMatchSnapshot(); }); - test(`should compile implemented class`, () => { + test(`should compile Enum`, () => { expect( TestApp.compileTemplate(reflectionTemplate, { - model: testApp.findReflection('ImplementedClass'), + model: testApp.findReflection('EnumReflection'), project: testApp.project, }), ).toMatchSnapshot(); diff --git a/packages/typedoc-plugin-markdown/test/specs/signatures.spec.ts b/packages/typedoc-plugin-markdown/test/specs/signatures.spec.ts index 6a6ac8b2e..28d4d2802 100644 --- a/packages/typedoc-plugin-markdown/test/specs/signatures.spec.ts +++ b/packages/typedoc-plugin-markdown/test/specs/signatures.spec.ts @@ -6,11 +6,14 @@ import { TestApp } from '../test-app'; describe(`Signatures:`, () => { let testApp: TestApp; let partial: Handlebars.TemplateDelegate; + let reflectionTemplate: Handlebars.TemplateDelegate; + beforeAll(async () => { testApp = new TestApp(['signatures.ts']); await testApp.bootstrap(); TestApp.stubPartials(['member.sources']); partial = TestApp.getPartial('member.signature'); + reflectionTemplate = TestApp.getTemplate('reflection'); }); test(`should compile callable signature'`, () => { @@ -62,16 +65,6 @@ describe(`Signatures:`, () => { ).toMatchSnapshot(); }); - test(`should compile signature with type params'`, () => { - expect( - TestApp.compileTemplate( - partial, - testApp.findReflection('functionWithTypeParams') - .signatures[0] as SignatureReflection, - ), - ).toMatchSnapshot(); - }); - test(`should compile signature with rest params'`, () => { expect( TestApp.compileTemplate( @@ -171,4 +164,14 @@ describe(`Signatures:`, () => { ), ).toMatchSnapshot(); }); + + test(`should compile class with constructor'`, () => { + expect( + TestApp.compileTemplate( + partial, + testApp.findReflection('ClassWithConstructor').children[0] + .signatures[0] as SignatureReflection, + ), + ).toMatchSnapshot(); + }); }); diff --git a/packages/typedoc-plugin-markdown/test/specs/sources.spec.ts b/packages/typedoc-plugin-markdown/test/specs/sources.spec.ts index b1ce5547b..3858628c0 100644 --- a/packages/typedoc-plugin-markdown/test/specs/sources.spec.ts +++ b/packages/typedoc-plugin-markdown/test/specs/sources.spec.ts @@ -30,7 +30,7 @@ describe(`Sources:`, () => { ).toMatchSnapshot(); }); - test(`should display inherited and overide sources'`, () => { + test(`should display inherited sources'`, () => { expect( TestApp.compileTemplate( partial, @@ -38,4 +38,13 @@ describe(`Sources:`, () => { ), ).toMatchSnapshot(); }); + + test(`should display overide sources'`, () => { + expect( + TestApp.compileTemplate( + partial, + getProp(testApp.findReflection('AnotherClass')), + ), + ).toMatchSnapshot(); + }); }); diff --git a/packages/typedoc-plugin-markdown/test/stubs/src/comments.ts b/packages/typedoc-plugin-markdown/test/stubs/src/comments.ts index 37494233f..d283909e6 100755 --- a/packages/typedoc-plugin-markdown/test/stubs/src/comments.ts +++ b/packages/typedoc-plugin-markdown/test/stubs/src/comments.ts @@ -93,13 +93,12 @@ export class CommentClass { } } -export const objectWithBlockComments = { +/** + * Some comments + */ +export type literalWithBlockComments = { /** - * Comment 1 - * - * @tag Tag description - * - * Comment 2 + * Comment for prop */ - prop: 'prop', + prop: string; }; diff --git a/packages/typedoc-plugin-markdown/test/stubs/src/declarations.ts b/packages/typedoc-plugin-markdown/test/stubs/src/declarations.ts index ef9ca0987..2e719938c 100644 --- a/packages/typedoc-plugin-markdown/test/stubs/src/declarations.ts +++ b/packages/typedoc-plugin-markdown/test/stubs/src/declarations.ts @@ -1,10 +1,13 @@ -export const stringWithDefaultValueDeclaration = 'variable'; +export const stringConstWithDefaultValue = 'hello'; +export let stringLetWithDefaultValue = 'hello'; +stringLetWithDefaultValue = 'world'; + export let undefinedNumberDeclaration: number; /** - * @param {Object} objectLiteralDeclaration description - * @param {string} objectLiteralDeclaration.valueZ description for valuez - * @param {number} objectLiteralDeclaration.valueA description for valuea + * @param objectLiteralDeclaration.valueX description for valueX + * @param objectLiteralDeclaration.valueZ description for valueZ + * @param objectLiteralDeclaration.valueY description for valueY */ export const objectLiteralDeclaration = { /** @@ -32,10 +35,6 @@ export const objectLiteralDeclaration = { valueC: {}, }; -export const objectLiteral2Declaration = { - valueA: () => {}, -}; - export let typeLiteralDeclaration: { /** * Comment for valueZ @@ -60,9 +59,17 @@ export let typeLiteralDeclaration: { valueB?: boolean; }; -export let typeLiteralDeclarationWithFunction: { - (): string; - valueZ: string; +export let functionDeclaration: (someArg: number) => boolean; + +export let callableDeclaration: { + (someArg: number): boolean; + arg1: string; + arg2: number; +}; + +export let indexableDeclaration: { + [index: number]: string; + arg1: string; }; /** @@ -81,17 +88,9 @@ export const __DOUBLE_UNDERSCORES_DECLARATION__ = Symbol.for('__type__'); export type AnyFunctionType = (...input: any[]) => A; -export type SpecialCharacters = { - this_prop_has_underscores: number; - 'this|prop|has|the|pipe|character': string; -}; - export enum EnumDeclarations { Up = 'UP', Down = 'DOWN', Left = 'LEFT', Right = 'RIGHT', } - -export const fooBigInt = BigInt(100); // the BigInt function -export const barBigInt = 100n; // a BigInt literal diff --git a/packages/typedoc-plugin-markdown/test/stubs/src/generics.ts b/packages/typedoc-plugin-markdown/test/stubs/src/generics.ts new file mode 100644 index 000000000..ed5a0a1d6 --- /dev/null +++ b/packages/typedoc-plugin-markdown/test/stubs/src/generics.ts @@ -0,0 +1,29 @@ +/** + * Comments for typeParams + * @typeparam T - Some type param + * @typeparam V - Some other type param + */ +export class ClassWithTypeParams { + propT: T; + propV: V; +} + +export const functionWithTypeParam = () => true; + +/** + * + * @typeParam A Comment for type `A` + * @typeParam B Comment for type `B` + */ +export const functionWithTypeParams = < + A extends ClassWithTypeParams, + B = boolean | string, + C = string +>() => true; + +export function functionWithGenericConstraints( + obj: Type, + key: Key, +) { + return obj[key]; +} diff --git a/packages/typedoc-plugin-markdown/test/stubs/src/index.ts b/packages/typedoc-plugin-markdown/test/stubs/src/index.ts index 177da08d0..3ee5712d3 100644 --- a/packages/typedoc-plugin-markdown/test/stubs/src/index.ts +++ b/packages/typedoc-plugin-markdown/test/stubs/src/index.ts @@ -3,6 +3,7 @@ export * as categories from './categories'; export * as comments from './comments'; export * as declarations from './declarations'; export * as frontmatter from './frontmatter'; +export * as generics from './generics'; export * as hierarchy from './hierarchy'; export * as members from './members'; export * as reflections from './reflections'; diff --git a/packages/typedoc-plugin-markdown/test/stubs/src/reflections.ts b/packages/typedoc-plugin-markdown/test/stubs/src/reflections.ts index bc367be3c..5737e121b 100644 --- a/packages/typedoc-plugin-markdown/test/stubs/src/reflections.ts +++ b/packages/typedoc-plugin-markdown/test/stubs/src/reflections.ts @@ -3,16 +3,6 @@ */ export class ReflectionClass {} -/** - * Comments for typeParams - * @typeparam T - Some type param - * @typeparam V - Some other type param - */ -export interface ReflectionWithTypeParams { - propT: T; - propV: V; -} - export interface CallableReflection { (): string; } diff --git a/packages/typedoc-plugin-markdown/test/stubs/src/signatures.ts b/packages/typedoc-plugin-markdown/test/stubs/src/signatures.ts index 83571b026..581264bf0 100644 --- a/packages/typedoc-plugin-markdown/test/stubs/src/signatures.ts +++ b/packages/typedoc-plugin-markdown/test/stubs/src/signatures.ts @@ -114,12 +114,20 @@ export function privateFunction() { export const functionWithTypeParams = () => true; +/** + * Comments for function + * @returns Return comments + */ export function functionReturningAnObject() { return { x: 1, y: 2 }; } +/** + * Comments for function + * @returns Return comments + */ export function functionReturningAFunction() { - return () => true; + return (x: string) => true; } /** @@ -200,3 +208,7 @@ export function functionWithNestedParams( ) { return true; } + +export class ClassWithConstructor { + constructor(x: string, y: string) {} +} diff --git a/packages/typedoc-plugin-markdown/test/stubs/src/types.ts b/packages/typedoc-plugin-markdown/test/stubs/src/types.ts index d0ac1d7bf..022a30b2a 100644 --- a/packages/typedoc-plugin-markdown/test/stubs/src/types.ts +++ b/packages/typedoc-plugin-markdown/test/stubs/src/types.ts @@ -67,7 +67,7 @@ export type intersectionType = IntersectionClassA & IntersectionClassB; export const arrayType: string[] = ['Apple', 'Orange', 'Banana']; -export function restUntionTypes( +export function restUnionTypes( arg: boolean[] | number, ...args: (string | number)[] ): any { @@ -101,3 +101,9 @@ export type ConditionalType = T extends string : T extends undefined ? 'undefined' : 'object'; + +export type Bar = (foos: ConditionalType[]) => R; // defined elsewhere +export const baz: Bar = (foos) => '...'; + +export const fooBigInt = BigInt(100); // the BigInt function +export const barBigInt = 100n; // a BigInt literal