Skip to content

Commit f7aa8bd

Browse files
committed
Fix #2842
1 parent 1709353 commit f7aa8bd

File tree

5 files changed

+35
-2
lines changed

5 files changed

+35
-2
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ title: Changelog
1414

1515
- Fixed an issue where TypeDoc would incorrectly ignore type arguments in references, #2823.
1616
- Improved narrator support for labeling icons, #2832.
17+
- Fixed an issue with `@class` incorrectly handling mapped types, #2842.
1718

1819
### Thanks!
1920

scripts/testcase.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ async function main() {
4646
const data = JSON.parse(await exec(curl.replace("ISSUE", issue)));
4747

4848
const parser = md();
49-
const tokens = parser.parse(data.body, {});
49+
const tokens = parser.parse(data.body || "", {});
5050

5151
const code =
5252
tokens.find(

src/lib/converter/symbols.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -720,8 +720,13 @@ function convertProperty(
720720
}
721721

722722
// Special case: We pretend properties are methods if they look like methods.
723-
// This happens with mixins / weird inheritance.
723+
// This happens with mixins / weird inheritance. Don't do this if the type
724+
// doesn't have call signatures to avoid converting non-functions. This can
725+
// happen if @class is used and functions are converted to their return type
726+
// with a mapped type (e.g. with Vue's `computed` properties)
727+
const type = context.checker.getTypeOfSymbol(symbol);
724728
if (
729+
type.getCallSignatures().length &&
725730
declarations.length &&
726731
declarations.every(
727732
(decl) =>

src/test/converter2/issues/gh2842.ts

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
declare function defineComponent<
2+
T extends Record<string, () => any>,
3+
U extends Record<string, any>,
4+
>(component: {
5+
computed: T;
6+
props: U;
7+
}): new () => U & { [K in keyof T]: ReturnType<T[K]> };
8+
9+
/** @class */
10+
export const ComputedClass = defineComponent({
11+
computed: {
12+
hello() {
13+
return "hello";
14+
},
15+
},
16+
props: {
17+
name: "world",
18+
},
19+
});

src/test/issues.c2.test.ts

+8
Original file line numberDiff line numberDiff line change
@@ -2014,4 +2014,12 @@ describe("Issue Tests", () => {
20142014
equal(returnTypes, expectedTypes);
20152015
equal(paramTypes, expectedTypes);
20162016
});
2017+
2018+
it("#2842 handles computed properties with @class", () => {
2019+
const project = convert();
2020+
const hello = query(project, "ComputedClass.hello");
2021+
2022+
equal(hello.kind, ReflectionKind.Property);
2023+
equal(hello.type?.toString(), "string");
2024+
});
20172025
});

0 commit comments

Comments
 (0)