Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a041c2d

Browse files
authored
fix(metadata): fix thunk type detection (#2125)
1 parent 9889b3b commit a041c2d

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

.changeset/mean-colts-hunt.md

+5
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

+1-1
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

+8
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)