Skip to content

fix(core): format of optional type and getter/setter #804

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { ParameterReflection, SomeType } from 'typedoc';
export function signatureParameters(
this: MarkdownThemeContext,
model: ParameterReflection[],
options?: { forceExpandParameters?: boolean },
) {
const format = this.options.getValue('useCodeBlocks');
const firstOptionalParamIndex = model.findIndex(
Expand All @@ -19,14 +20,15 @@ export function signatureParameters(
paramsmd.push('...');
}
const paramType = this.partials.someType(param.type as SomeType);
const showParamType = this.options.getValue('expandParameters');
const optional = param.flags.isOptional ||
(firstOptionalParamIndex !== -1 && i > firstOptionalParamIndex)
? '?'
: ''
const paramItem = [
`${backTicks(`${param.name}${optional}`)}`,
];
const showParamType =
(options?.forceExpandParameters ?? false) ||
this.options.getValue('expandParameters');
const optional =
param.flags.isOptional ||
(firstOptionalParamIndex !== -1 && i > firstOptionalParamIndex)
? '?'
: '';
const paramItem = [`${backTicks(`${param.name}${optional}`)}`];
if (showParamType) {
paramItem.push(paramType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,21 @@ export function declarationType(

if (obj.getSignature) {
name.push('get');
name.push(backTicks(obj.name) + '\n ');
}

if (obj.setSignature) {
name.push(backTicks(obj.name) + '()');
} else if (obj.setSignature) {
name.push('set');
name.push(backTicks(obj.name));
const params = obj.setSignature.parameters
? this.partials.signatureParameters(obj.setSignature.parameters, {
forceExpandParameters: true,
})
: '()';
name.push(backTicks(obj.name) + params);
} else {
const displayObjectName =
obj.name + (obj.flags?.isOptional ? '?' : '');
name.push(backTicks(displayObjectName));
}

name.push(backTicks(obj.name));

const theType = this.helpers.getDeclarationType(obj) as SomeType;

const typeString = this.partials.someType(theType, options);
Expand All @@ -67,6 +72,7 @@ export function declarationType(
);
}
}

md.push(`${shouldFormat ? '' : ' '}\\}`);
return md.join(shouldFormat ? '\n' : '');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,11 @@ There is no association list partial for properties as these are handled as a st
hideTitle?: boolean | undefined;
},
) => partials.signature.apply(context, [model, options]) as string,
signatureParameters: (model: ParameterReflection[]) =>
partials.signatureParameters.apply(context, [model]) as string,
signatureParameters: (
model: ParameterReflection[],
options?: { forceExpandParameters?: boolean | undefined } | undefined,
) =>
partials.signatureParameters.apply(context, [model, options]) as string,
signatureReturns: (
model: SignatureReflection,
options: { headingLevel: number },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ Comments for propWithFunction

### propWithProps

> **propWithProps**: \\{ \`callbacks\`: \`Partial\`\\<[\`CallbacksOptions\`](../classes/CallbacksOptions.md)\\<[\`DisposableClass\`](../classes/DisposableClass.md), [\`ClassWithModifiers\`](../classes/ClassWithModifiers.md)\\>\\>; \`nestedPropA\`: \`string\`; \`nestedPropB\`: \`boolean\`; \`nestedPropC\`: \\{ \`nestedPropCA\`: \`string\`; \\}; \`nestedPropD\`: () => \`boolean\`; \\}
> **propWithProps**: \\{ \`callbacks?\`: \`Partial\`\\<[\`CallbacksOptions\`](../classes/CallbacksOptions.md)\\<[\`DisposableClass\`](../classes/DisposableClass.md), [\`ClassWithModifiers\`](../classes/ClassWithModifiers.md)\\>\\>; \`nestedPropA\`: \`string\`; \`nestedPropB\`: \`boolean\`; \`nestedPropC\`: \\{ \`nestedPropCA\`: \`string\`; \\}; \`nestedPropD\`: () => \`boolean\`; \\}

Comments for propWithProps

Expand Down Expand Up @@ -221,7 +221,7 @@ Comments for BasicInterface
| <a id="propreturningsignaturedeclaration"></a> \`propReturningSignatureDeclaration?\` | () => \`string\` \\| \`number\` \\| \`boolean\` | Comments for propReturningSignatureDeclaration |
| <a id="propreturningsignaturedeclarations"></a> \`propReturningSignatureDeclarations\` | () => \`any\` & (\`paramsA\`: \`true\` \\| \`any\`[], \`paramsB?\`: \`any\`) => \`any\` & (\`paramsC\`: \`any\`) => \`any\` | Comments for propReturningSignatureDeclarations |
| <a id="propwithfunction"></a> \`propWithFunction\` | (\`options\`: \\{ \`a\`: \`boolean\`; \`b\`: \`string\`; \\}) => \`boolean\` | Comments for propWithFunction |
| <a id="propwithprops"></a> \`propWithProps\` | \\{ \`callbacks\`: \`Partial\`\\<[\`CallbacksOptions\`](../classes/CallbacksOptions.md)\\<[\`DisposableClass\`](../classes/DisposableClass.md), [\`ClassWithModifiers\`](../classes/ClassWithModifiers.md)\\>\\>; \`nestedPropA\`: \`string\`; \`nestedPropB\`: \`boolean\`; \`nestedPropC\`: \\{ \`nestedPropCA\`: \`string\`; \\}; \`nestedPropD\`: () => \`boolean\`; \\} | Comments for propWithProps |
| <a id="propwithprops"></a> \`propWithProps\` | \\{ \`callbacks?\`: \`Partial\`\\<[\`CallbacksOptions\`](../classes/CallbacksOptions.md)\\<[\`DisposableClass\`](../classes/DisposableClass.md), [\`ClassWithModifiers\`](../classes/ClassWithModifiers.md)\\>\\>; \`nestedPropA\`: \`string\`; \`nestedPropB\`: \`boolean\`; \`nestedPropC\`: \\{ \`nestedPropCA\`: \`string\`; \\}; \`nestedPropD\`: () => \`boolean\`; \\} | Comments for propWithProps |
| \`propWithProps.callbacks?\` | \`Partial\`\\<[\`CallbacksOptions\`](../classes/CallbacksOptions.md)\\<[\`DisposableClass\`](../classes/DisposableClass.md), [\`ClassWithModifiers\`](../classes/ClassWithModifiers.md)\\>\\> | Comments for callbacks |
| \`propWithProps.nestedPropA\` | \`string\` | Comments for nestedPropA |
| \`propWithProps.nestedPropB\` | \`boolean\` | Comments for nestedPropB |
Expand Down Expand Up @@ -362,7 +362,7 @@ y: number = 2;
exports[`Objects And Params should compile function with nested parameters: (Output File Strategy "members") (Option Group "1") 1`] = `
"# Function: functionWithNestedParameters()

> **functionWithNestedParameters**(\`params\`: \\{ \`name\`: \`string\`; \`nestedObj\`: \\{ \`name\`: \`string\`; \`obj\`: \\{ \`name\`: () => \`void\`; \\}; \`value\`: \`number\`; \\}; \`parent\`: \`number\`; \\}, \`context\`: \`any\`, \`somethingElse?\`: \`string\`): \`boolean\`
> **functionWithNestedParameters**(\`params\`: \\{ \`name\`: \`string\`; \`nestedObj\`: \\{ \`name\`: \`string\`; \`obj\`: \\{ \`name\`: () => \`void\`; \\}; \`value\`: \`number\`; \\}; \`parent?\`: \`number\`; \\}, \`context\`: \`any\`, \`somethingElse?\`: \`string\`): \`boolean\`

Some nested params.

Expand Down Expand Up @@ -434,7 +434,7 @@ function functionWithNestedParameters(
};
value: number;
};
parent: number;
parent?: number;
},
context: any,
somethingElse?: string): boolean;
Expand All @@ -446,7 +446,7 @@ Some nested params.

| Parameter | Type | Description |
| :------ | :------ | :------ |
| \`params\` | \\{ \`name\`: \`string\`; \`nestedObj\`: \\{ \`name\`: \`string\`; \`obj\`: \\{ \`name\`: () => \`void\`; \\}; \`value\`: \`number\`; \\}; \`parent\`: \`number\`; \\} | The parameters passed to the method. |
| \`params\` | \\{ \`name\`: \`string\`; \`nestedObj\`: \\{ \`name\`: \`string\`; \`obj\`: \\{ \`name\`: () => \`void\`; \\}; \`value\`: \`number\`; \\}; \`parent?\`: \`number\`; \\} | The parameters passed to the method. |
| \`params.name\` | \`string\` | The name of the new group. |
| \`params.nestedObj\` | \\{ \`name\`: \`string\`; \`obj\`: \\{ \`name\`: () => \`void\`; \\}; \`value\`: \`number\`; \\} | A nested object. |
| \`params.nestedObj.name?\` | \`string\` | - |
Expand Down Expand Up @@ -502,9 +502,7 @@ bar: number;
exports[`Objects And Params should compile literal type: (Output File Strategy "members") (Option Group "1") 1`] = `
"# Type Alias: LiteralType

> **LiteralType** = \\{ \`someFunctionWithArrow\`: () => \`string\`; \`x\`: \`string\`; \`y\`: \\{ \`x\`: \`string\`; \`y\`: \`boolean\` \\| \`string\`; \`z\`: (\`x\`: \`string\`) => \`string\`; \\}; \`z\`: (\`x\`: \`string\`) => \`string\`; get \`accessorA\`
set \`accessorA\` \`accessorA\`: [\`Promise\`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)\\<\`string\`\\>; get \`accessorB\`
set \`accessorB\` \`accessorB\`: \`string\`; \`someFunction\`: [\`Promise\`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)\\<\`any\`\\>; \\}
> **LiteralType** = \\{ \`someFunctionWithArrow\`: () => \`string\`; \`x?\`: \`string\`; \`y\`: \\{ \`x\`: \`string\`; \`y?\`: \`boolean\` \\| \`string\`; \`z\`: (\`x\`: \`string\`) => \`string\`; \\}; \`z\`: (\`x\`: \`string\`) => \`string\`; get \`accessorA\`(): [\`Promise\`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)\\<\`string\`\\>; get \`accessorB\`(): \`string\`; \`someFunction\`: [\`Promise\`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)\\<\`any\`\\>; \\}

Comments for LiteralType

Expand Down Expand Up @@ -532,7 +530,7 @@ comment for x

### y

> **y**: \\{ \`x\`: \`string\`; \`y\`: \`boolean\` \\| \`string\`; \`z\`: (\`x\`: \`string\`) => \`string\`; \\}
> **y**: \\{ \`x\`: \`string\`; \`y?\`: \`boolean\` \\| \`string\`; \`z\`: (\`x\`: \`string\`) => \`string\`; \\}

comment for y

Expand Down Expand Up @@ -662,17 +660,15 @@ exports[`Objects And Params should compile literal type: (Output File Strategy "
\`\`\`ts
type LiteralType = {
someFunctionWithArrow: () => string;
x: string;
x?: string;
y: {
x: string;
y: boolean | string;
y?: boolean | string;
z: (x: string) => string;
};
z: (x: string) => string;
get accessorA
set accessorA accessorA: Promise<string>;
get accessorB
set accessorB accessorB: string;
get accessorA(): Promise<string>;
get accessorB(): string;
someFunction: Promise<any>;
};
\`\`\`
Expand Down Expand Up @@ -710,7 +706,7 @@ comment for x
\`\`\`ts
y: {
x: string;
y: boolean | string;
y?: boolean | string;
z: (x: string) => string;
};
\`\`\`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1101,7 +1101,7 @@ Defined in: [functions.ts:1](http://source-url)

| Parameter | Type | Description |
| :------ | :------ | :------ |
| \`__namedParameters\` | \\{ \`bar\`: \`number\`; \`foo\`: \`number\`; \\} | various options |
| \`__namedParameters\` | \\{ \`bar?\`: \`number\`; \`foo?\`: \`number\`; \\} | various options |
| \`__namedParameters.bar?\` | \`number\` | - |
| \`__namedParameters.foo?\` | \`number\` | - |
| \`anotherParam\` | \`string\` | Another param comment |
Expand Down Expand Up @@ -1193,7 +1193,7 @@ Some nested params.

| Parameter | Type | Description |
| :------ | :------ | :------ |
| \`params\` | \\{ \`name\`: \`string\`; \`nestedObj\`: \\{ \`name\`: \`string\`; \`obj\`: \\{ \`name\`: () => \`void\`; \\}; \`value\`: \`number\`; \\}; \`parent\`: \`number\`; \\} | The parameters passed to the method. |
| \`params\` | \\{ \`name\`: \`string\`; \`nestedObj\`: \\{ \`name\`: \`string\`; \`obj\`: \\{ \`name\`: () => \`void\`; \\}; \`value\`: \`number\`; \\}; \`parent?\`: \`number\`; \\} | The parameters passed to the method. |
| \`params.name\` | \`string\` | The name of the new group. |
| \`params.nestedObj\` | \\{ \`name\`: \`string\`; \`obj\`: \\{ \`name\`: () => \`void\`; \\}; \`value\`: \`number\`; \\} | A nested object. |
| \`params.nestedObj.name?\` | \`string\` | - |
Expand Down