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

Fix session type after changing Customer Account client #1869

Merged
merged 3 commits into from
Mar 21, 2024
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
22 changes: 22 additions & 0 deletions .changeset/twenty-taxis-taste.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
'skeleton': patch
---

Fix types returned by the `session` object.
In `remix.env.d.ts` or `env.d.ts`, add the following types:

```diff
import type {
// ...
HydrogenCart,
+ HydrogenSessionData,
} from '@shopify/hydrogen';

// ...

declare module '@shopify/remix-oxygen' {
// ...

+ interface SessionData extends HydrogenSessionData {}
}
```
8 changes: 7 additions & 1 deletion examples/custom-cart-method/remix.env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type {
CustomerAccount,
HydrogenCart,
HydrogenCartCustom,
HydrogenSessionData,
CartQueryDataReturn,
} from '@shopify/hydrogen';
import type {
Expand Down Expand Up @@ -42,7 +43,7 @@ declare module '@shopify/remix-oxygen' {
/**
* Declare local additions to the Remix loader context.
*/
export interface AppLoadContext {
interface AppLoadContext {
env: Env;
/***********************************************/
/********** EXAMPLE UPDATE STARTS ************/
Expand All @@ -60,4 +61,9 @@ declare module '@shopify/remix-oxygen' {
session: AppSession;
waitUntil: ExecutionContext['waitUntil'];
}

/**
* Declare local additions to the Remix session data.
*/
interface SessionData extends HydrogenSessionData {}
}
8 changes: 7 additions & 1 deletion examples/metaobjects/remix.env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {
Storefront,
CustomerAccount,
HydrogenCart,
HydrogenSessionData,
} from '@shopify/hydrogen';
import type {AppSession} from '~/lib/session';

Expand Down Expand Up @@ -41,12 +42,17 @@ declare module '@shopify/remix-oxygen' {
/**
* Declare local additions to the Remix loader context.
*/
export interface AppLoadContext {
interface AppLoadContext {
env: Env;
cart: HydrogenCart;
storefront: Storefront;
customerAccount: CustomerAccount;
session: AppSession;
waitUntil: ExecutionContext['waitUntil'];
}

/**
* Declare local additions to the Remix session data.
*/
interface SessionData extends HydrogenSessionData {}
}
6 changes: 6 additions & 0 deletions examples/third-party-queries-caching/remix.env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {
Storefront,
CustomerAccount,
HydrogenCart,
HydrogenSessionData,
} from '@shopify/hydrogen';
import type {AppSession} from '~/lib/session';
import {createRickAndMortyClient} from './app/lib/createRickAndMortyClient.server';
Expand Down Expand Up @@ -46,4 +47,9 @@ declare module '@shopify/remix-oxygen' {
session: AppSession;
waitUntil: ExecutionContext['waitUntil'];
}

/**
* Declare local additions to the Remix session data.
*/
interface SessionData extends HydrogenSessionData {}
}
8 changes: 7 additions & 1 deletion examples/vite/env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {
Storefront,
CustomerAccount,
HydrogenCart,
HydrogenSessionData,
} from '@shopify/hydrogen';
import type {AppSession} from '~/lib/session';

Expand Down Expand Up @@ -36,12 +37,17 @@ declare module '@shopify/remix-oxygen' {
/**
* Declare local additions to the Remix loader context.
*/
export interface AppLoadContext {
interface AppLoadContext {
env: Env;
cart: HydrogenCart;
storefront: Storefront;
customerAccount: CustomerAccount;
session: AppSession;
waitUntil: ExecutionContext['waitUntil'];
}

/**
* Declare local additions to the Remix session data.
*/
interface SessionData extends HydrogenSessionData {}
}
10 changes: 7 additions & 3 deletions packages/cli/src/lib/transpile/morph/typedefs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,24 @@ export function generateTypeDefs(sourceFile: SourceFile, code: string) {

typedefs.push(''); // New line

const knownGenerics: Record<string, string | undefined> = {
MetaFunction: 'T',
};

typedefsFromImports.forEach((typeElements, moduleSpecifier) => {
for (const typeElement of typeElements) {
// We only use this in root.tsx and it's better to
// reuse the existing LoaderReturnData, so skip it.
if (typeElement === 'SerializeFrom') continue;

// Note: SerializeFrom also needs generic if we stop skipping it.
const hasGeneric = typeElement === 'MetaFunction';
const hasGeneric = !!knownGenerics[typeElement];

typedefs.push(
`/** ${
hasGeneric ? '@template T ' : ''
hasGeneric ? `@template ${knownGenerics[typeElement]} ` : ''
}@typedef {import('${moduleSpecifier}').${typeElement}${
hasGeneric ? '<T>' : ''
hasGeneric ? `<${knownGenerics[typeElement]}>` : ''
}} ${typeElement} */`,
);
}
Expand Down
8 changes: 7 additions & 1 deletion templates/skeleton/remix.env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {
Storefront,
CustomerAccount,
HydrogenCart,
HydrogenSessionData,
} from '@shopify/hydrogen';
import type {AppSession} from '~/lib/session';

Expand Down Expand Up @@ -36,12 +37,17 @@ declare module '@shopify/remix-oxygen' {
/**
* Declare local additions to the Remix loader context.
*/
export interface AppLoadContext {
interface AppLoadContext {
env: Env;
cart: HydrogenCart;
storefront: Storefront;
customerAccount: CustomerAccount;
session: AppSession;
waitUntil: ExecutionContext['waitUntil'];
}

/**
* Declare local additions to the Remix session data.
*/
interface SessionData extends HydrogenSessionData {}
}
Loading