From ead2198ce1a88a7a91b96c50a9c085d563f065ea Mon Sep 17 00:00:00 2001 From: wangzhiyusss Date: Thu, 24 Jul 2025 15:24:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DintTonumber=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangzhiyusss --- build-tools/intToNumber.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/build-tools/intToNumber.js b/build-tools/intToNumber.js index 8bcedc0c0b..310be81d72 100644 --- a/build-tools/intToNumber.js +++ b/build-tools/intToNumber.js @@ -302,12 +302,21 @@ function applJSDocTransformations(typeExpr, newTypeExpr, tagDataList, isChange) const printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed }); const finalContent = printer.printNode(ts.EmitHint.Unspecified, newTypeExpr); if (finalContent.includes('number') && typeExpr.kind === ts.SyntaxKind.JSDocNullableType && !finalContent.includes('?number') && isChange) { - const data = { - pos: typeExpr.pos, - end: typeExpr.end, - convertedText: '?' + finalContent - }; - tagDataList.push(data); + if (typeExpr.type.type && typeExpr.type.type.kind === ts.SyntaxKind.UnionType) { + const data = { + pos: typeExpr.pos, + end: typeExpr.end, + convertedText: '?' + `(${finalContent})` + }; + tagDataList.push(data); + } else { + const data = { + pos: typeExpr.pos, + end: typeExpr.end, + convertedText: '?' + finalContent + }; + tagDataList.push(data); + } } else if (finalContent.includes('number')) { const data = { pos: typeExpr.pos, -- Gitee