Skip to content
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

TS stuff #257

Closed
wants to merge 3 commits into from
Closed

TS stuff #257

wants to merge 3 commits into from

Conversation

frehner
Copy link
Contributor

@frehner frehner commented Nov 29, 2022

This is as good as I can get it I think. There is some manual casting you have to do inside of getAnalyticDataByPageType, but users of it don't have to do any. 🤷

@@ -11,6 +12,27 @@ import invariant from 'tiny-invariant';
export async function loader({request, context: {storefront}}: LoaderArgs) {
const url = new URL(request.url);

const data = await getAnalyticDataByPageType({
Copy link
Contributor Author

Choose a reason for hiding this comment

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

data, data2, and data3 should all be correctly typed. So, at least for users of this function, it should "just work".

pageType: string;
payload: unknown;
pageType: T;
payload: PageToPayloadMap[T];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For some reason TS can't figure this out, so you have to cast (as noted in the comments below)

storefront: LoaderArgs['context']['storefront'];
queries: AnalyticsQueries;
}) {
}): Promise<PageToPayloadMap[T]> {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

And yet, TS can figure this one out. So 🤷

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.

1 participant