mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
fix(website): nullable parameters on events (#10510)
This commit is contained in:
@@ -1510,15 +1510,17 @@ export class ApiModelGenerator {
|
||||
const excerptTokens: IExcerptToken[] = [
|
||||
{
|
||||
kind: ExcerptTokenKind.Content,
|
||||
text: `on('${name}', (${
|
||||
jsDoc.params?.length ? `${jsDoc.params[0]?.name}${jsDoc.params[0]?.nullable ? '?' : ''}: ` : ') => {})'
|
||||
text: `public on(eventName: '${name}', listener: (${
|
||||
jsDoc.params?.length
|
||||
? `${jsDoc.params[0]?.name}${jsDoc.params[0]?.optional ? '?' : ''}: `
|
||||
: ') => void): this;'
|
||||
}`,
|
||||
},
|
||||
];
|
||||
const parameters: IApiParameterOptions[] = [];
|
||||
for (let index = 0; index < (jsDoc.params?.length ?? 0) - 1; index++) {
|
||||
const parameter = jsDoc.params![index]!;
|
||||
const newTokens = this._mapVarType(parameter.type);
|
||||
const newTokens = this._mapVarType(parameter.type, parameter.nullable);
|
||||
parameters.push({
|
||||
parameterName: parameter.name,
|
||||
parameterTypeTokenRange: {
|
||||
@@ -1537,7 +1539,7 @@ export class ApiModelGenerator {
|
||||
|
||||
if (jsDoc.params?.length) {
|
||||
const parameter = jsDoc.params![jsDoc.params.length - 1]!;
|
||||
const newTokens = this._mapVarType(parameter.type);
|
||||
const newTokens = this._mapVarType(parameter.type, parameter.nullable);
|
||||
parameters.push({
|
||||
parameterName: parameter.name,
|
||||
parameterTypeTokenRange: {
|
||||
@@ -1550,7 +1552,7 @@ export class ApiModelGenerator {
|
||||
excerptTokens.push(...newTokens);
|
||||
excerptTokens.push({
|
||||
kind: ExcerptTokenKind.Content,
|
||||
text: `) => {})`,
|
||||
text: `) => void): this;`,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1773,7 +1775,7 @@ export class ApiModelGenerator {
|
||||
.replaceAll('* ', '\n * * ');
|
||||
}
|
||||
|
||||
private _mapVarType(typey: DocgenVarTypeJson): IExcerptToken[] {
|
||||
private _mapVarType(typey: DocgenVarTypeJson, nullable?: boolean): IExcerptToken[] {
|
||||
const mapper = Array.isArray(typey) ? typey : (typey.types ?? []);
|
||||
const lookup: { [K in ts.SyntaxKind]?: string } = {
|
||||
[ts.SyntaxKind.ClassDeclaration]: 'class',
|
||||
@@ -1816,7 +1818,22 @@ export class ApiModelGenerator {
|
||||
{ kind: ExcerptTokenKind.Content, text: symbol ?? '' },
|
||||
];
|
||||
}, []);
|
||||
return index === 0 ? result : [{ kind: ExcerptTokenKind.Content, text: ' | ' }, ...result];
|
||||
return index === 0
|
||||
? mapper.length === 1 && (nullable || ('nullable' in typey && typey.nullable))
|
||||
? [
|
||||
...result,
|
||||
{ kind: ExcerptTokenKind.Content, text: ' | ' },
|
||||
{ kind: ExcerptTokenKind.Reference, text: 'null' },
|
||||
]
|
||||
: result
|
||||
: index === mapper.length - 1 && (nullable || ('nullable' in typey && typey.nullable))
|
||||
? [
|
||||
{ kind: ExcerptTokenKind.Content, text: ' | ' },
|
||||
...result,
|
||||
{ kind: ExcerptTokenKind.Content, text: ' | ' },
|
||||
{ kind: ExcerptTokenKind.Reference, text: 'null' },
|
||||
]
|
||||
: [{ kind: ExcerptTokenKind.Content, text: ' | ' }, ...result];
|
||||
})
|
||||
.filter((excerpt) => excerpt.text.length);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user