diff --git a/CHANGELOG.md b/CHANGELOG.md index ec617ce4c..18280e1da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ title: Changelog ### Bug Fixes - Fixed an issue where TypeDoc would incorrectly ignore type arguments in references, #2823. +- Fixed an issue with `@class` incorrectly handling mapped types, #2842. ### Thanks! diff --git a/scripts/testcase.js b/scripts/testcase.js index 384c56bc0..a46ba7a65 100644 --- a/scripts/testcase.js +++ b/scripts/testcase.js @@ -46,7 +46,7 @@ async function main() { const data = JSON.parse(await exec(curl.replace("ISSUE", issue))); const parser = md(); - const tokens = parser.parse(data.body, {}); + const tokens = parser.parse(data.body || "", {}); const code = tokens.find( diff --git a/src/lib/converter/symbols.ts b/src/lib/converter/symbols.ts index 51a3f283b..902c29b6e 100644 --- a/src/lib/converter/symbols.ts +++ b/src/lib/converter/symbols.ts @@ -720,8 +720,13 @@ function convertProperty( } // Special case: We pretend properties are methods if they look like methods. - // This happens with mixins / weird inheritance. + // This happens with mixins / weird inheritance. Don't do this if the type + // doesn't have call signatures to avoid converting non-functions. This can + // happen if @class is used and functions are converted to their return type + // with a mapped type (e.g. with Vue's `computed` properties) + const type = context.checker.getTypeOfSymbol(symbol); if ( + type.getCallSignatures().length && declarations.length && declarations.every( (decl) => diff --git a/src/test/converter2/issues/gh2842.ts b/src/test/converter2/issues/gh2842.ts new file mode 100644 index 000000000..9b66f9276 --- /dev/null +++ b/src/test/converter2/issues/gh2842.ts @@ -0,0 +1,19 @@ +declare function defineComponent< + T extends Record any>, + U extends Record, +>(component: { + computed: T; + props: U; +}): new () => U & { [K in keyof T]: ReturnType }; + +/** @class */ +export const ComputedClass = defineComponent({ + computed: { + hello() { + return "hello"; + }, + }, + props: { + name: "world", + }, +}); diff --git a/src/test/issues.c2.test.ts b/src/test/issues.c2.test.ts index 57996b136..19aab8f86 100644 --- a/src/test/issues.c2.test.ts +++ b/src/test/issues.c2.test.ts @@ -2014,4 +2014,12 @@ describe("Issue Tests", () => { equal(returnTypes, expectedTypes); equal(paramTypes, expectedTypes); }); + + it("#2842 handles computed properties with @class", () => { + const project = convert(); + const hello = query(project, "ComputedClass.hello"); + + equal(hello.kind, ReflectionKind.Property); + equal(hello.type?.toString(), "string"); + }); });