Skip to content

Commit

Permalink
Fix #2842
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit0 committed Feb 2, 2025
1 parent 9ced135 commit 527a121
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!

Expand Down
2 changes: 1 addition & 1 deletion scripts/testcase.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
7 changes: 6 additions & 1 deletion src/lib/converter/symbols.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down
19 changes: 19 additions & 0 deletions src/test/converter2/issues/gh2842.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
declare function defineComponent<
T extends Record<string, () => any>,
U extends Record<string, any>,
>(component: {
computed: T;
props: U;
}): new () => U & { [K in keyof T]: ReturnType<T[K]> };

/** @class */
export const ComputedClass = defineComponent({
computed: {
hello() {
return "hello";
},
},
props: {
name: "world",
},
});
8 changes: 8 additions & 0 deletions src/test/issues.c2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
});

0 comments on commit 527a121

Please sign in to comment.