From 4d845ea83e6cd64b3883db472646fcef2d459b73 Mon Sep 17 00:00:00 2001 From: Jeongho Nam Date: Sun, 30 Jul 2023 05:23:13 +0900 Subject: [PATCH] Complement #726 - `JSDocParameterTag` case. New JSDoc API of TypeScript 5.1 is so difficult than expected. Maybe there will be a few more patches after that. --- package.json | 2 +- packages/typescript-json/package.json | 4 ++-- src/factories/CommentFactory.ts | 9 ++++++--- test/issues/comment-function.ts | 19 +++++++++++++++++++ 4 files changed, 28 insertions(+), 6 deletions(-) create mode 100644 test/issues/comment-function.ts diff --git a/package.json b/package.json index af104328a2..5dd4cbdae7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "typia", - "version": "4.1.10", + "version": "4.1.11", "description": "Superfast runtime validators with only one line", "main": "lib/index.js", "typings": "lib/index.d.ts", diff --git a/packages/typescript-json/package.json b/packages/typescript-json/package.json index 8a2e607daa..336fa2d3b9 100644 --- a/packages/typescript-json/package.json +++ b/packages/typescript-json/package.json @@ -1,6 +1,6 @@ { "name": "typescript-json", - "version": "4.1.10", + "version": "4.1.11", "description": "Superfast runtime validators with only one line", "main": "lib/index.js", "typings": "lib/index.d.ts", @@ -68,7 +68,7 @@ }, "homepage": "https://typia.io", "dependencies": { - "typia": "4.1.10" + "typia": "4.1.11" }, "peerDependencies": { "typescript": ">= 4.7.4" diff --git a/src/factories/CommentFactory.ts b/src/factories/CommentFactory.ts index fc156030e2..570df681fc 100644 --- a/src/factories/CommentFactory.ts +++ b/src/factories/CommentFactory.ts @@ -66,8 +66,11 @@ export namespace CommentFactory { } const parseJSDocTag = (tag: ts.JSDocTag): string => { + const name: string | undefined = ( + tag as ts.JSDocParameterTag + ).name?.getText(); const parsed: string | undefined = ts.getTextOfJSDocComment(tag.comment); - return parsed?.length - ? `@${tag.tagName.text} ${parsed}` - : `@${tag.tagName.text}`; + return [`@${tag.tagName.text}`, name, parsed] + .filter((str) => !!str?.length) + .join(" "); }; diff --git a/test/issues/comment-function.ts b/test/issues/comment-function.ts new file mode 100644 index 0000000000..8f68cc8a6d --- /dev/null +++ b/test/issues/comment-function.ts @@ -0,0 +1,19 @@ +import typia from "typia"; + +export interface IWrapper { + /** + * Compute two variables. + * + * @param x The first value + * @param y The second value + * @returns The result of computation + */ + compute: (x: number, y: number) => number; +} + +const article = typia.metadata<[IWrapper]>().collection.objects[0]; + +console.log( + article.properties.find((p) => p.key.constants[0]?.values[0] === "compute") + ?.description, +);