Skip to content

Commit 00e4d8e

Browse files
committed
fix(metadata): fix thunk type detection
1 parent 31bdbaf commit 00e4d8e

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

.changeset/mean-colts-hunt.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"openapi-metadata": patch
3+
---
4+
5+
[#2123](https://github.com/openapi-ts/openapi-typescript/issues/2123) Fix thunk type detection

packages/openapi-metadata/src/utils/metadata.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export function findType({ metadataKey, prototype, propertyKey }: FindTypeOption
3535
return reflectedType;
3636
}
3737

38-
const IS_THUNK_REG = /.+=>[\w\d\s\t\n\r]*/;
38+
const IS_THUNK_REG = /^.+=>[\w\d\s\t\n\r]*/;
3939

4040
/**
4141
* Asserts that a value is a thunk value.

packages/openapi-metadata/test/utils/metadata.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ test("isThunk", () => {
1212
expect(isThunk(User)).toBe(false);
1313
expect(isThunk(() => User)).toBe(true);
1414

15+
class InsideThunk {
16+
test() {
17+
return [].map(() => {});
18+
}
19+
}
20+
expect(isThunk(InsideThunk)).toBe(false);
21+
expect(isThunk(() => InsideThunk)).toBe(true);
22+
1523
expect(
1624
isThunk(() => {
1725
return "TESTEST";

0 commit comments

Comments
 (0)