-
Notifications
You must be signed in to change notification settings - Fork 281
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
TS stuff #257
Conversation
@@ -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({ |
There was a problem hiding this comment.
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]; |
There was a problem hiding this comment.
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]> { |
There was a problem hiding this comment.
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 🤷
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. 🤷