Skip to content

fix: allow Data to be inferred from Handler function#2916

Merged
marvinhagemeister merged 1 commit into
freshframework:mainfrom
csvn:fix/allow-handlerFn-data-resolve
May 12, 2025
Merged

fix: allow Data to be inferred from Handler function#2916
marvinhagemeister merged 1 commit into
freshframework:mainfrom
csvn:fix/allow-handlerFn-data-resolve

Conversation

@csvn

@csvn csvn commented May 10, 2025

Copy link
Copy Markdown
Contributor

This PR adds support for single-function GET handler data to be inferred when using define.page<typeof handler>().

export const handler = define.handlers((ctx) => {
  return page({ foo: "foo" });
});

export default define.page<typeof handler>((ctx) => {
  ctx.data; // Correctly resolves as { foo: string }
});

This PR also adds a test that checks that the types inferred are correct by type checking.

@marvinhagemeister marvinhagemeister left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks!

@marvinhagemeister marvinhagemeister merged commit a235961 into freshframework:main May 12, 2025
4 of 7 checks passed
@csvn csvn deleted the fix/allow-handlerFn-data-resolve branch May 21, 2025 09:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants