Skip to content

fix(metadata): fix thunk type detection #2125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/mean-colts-hunt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"openapi-metadata": patch
---

[#2123](https://github.com/openapi-ts/openapi-typescript/issues/2123) Fix thunk type detection
2 changes: 1 addition & 1 deletion packages/openapi-metadata/src/utils/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function findType({ metadataKey, prototype, propertyKey }: FindTypeOption
return reflectedType;
}

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

/**
* Asserts that a value is a thunk value.
Expand Down
8 changes: 8 additions & 0 deletions packages/openapi-metadata/test/utils/metadata.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ test("isThunk", () => {
expect(isThunk(User)).toBe(false);
expect(isThunk(() => User)).toBe(true);

class InsideThunk {
test() {
return [].map(() => {});
}
}
expect(isThunk(InsideThunk)).toBe(false);
expect(isThunk(() => InsideThunk)).toBe(true);

expect(
isThunk(() => {
return "TESTEST";
Expand Down
Loading