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 typescript #182

Merged
merged 3 commits into from
Nov 10, 2022
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
23 changes: 23 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,29 @@ jobs:
- name: 🔬 Lint
run: npm run lint

typecheck:
name: Typescript
runs-on: shopify-ubuntu-latest
steps:
- name: 🛑 Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.11.0

- name: ⬇️ Checkout repo
uses: actions/checkout@v3

- name: ⎔ Setup node
uses: actions/setup-node@v3
with:
node-version: 16

- name: 📥 Download deps
uses: bahmutov/npm-install@v1
with:
useLockFile: false

- name: ✅ Typecheck
run: npm run typecheck

test:
name: ⚫️ Playwright tests
timeout-minutes: 60
Expand Down
10 changes: 6 additions & 4 deletions app/components/Hero.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import clsx from 'clsx';
import {Image, Video} from '@shopify/hydrogen-react';
import type {
MediaImage,
Media,
Video as MediaVideo,
Metafield,
} from '@shopify/hydrogen-react/storefront-api-types';
import {Link} from '@remix-run/react';
Expand Down Expand Up @@ -66,7 +68,7 @@ export function Hero({
sizes="(min-width: 80em) 700, (min-width: 48em) 450, 500"
widths={[450, 700]}
width={375}
data={spreadSecondary.reference}
data={spreadSecondary.reference as Media}
/>
</div>
)}
Expand All @@ -90,7 +92,7 @@ export function Hero({
}

interface SpreadMediaProps {
data: Media;
data: Media | MediaImage | MediaVideo;
loading?: HTMLImageElement['loading'];
scale?: 2 | 3;
sizes: string;
Expand All @@ -112,7 +114,7 @@ function SpreadMedia({
previewImageOptions={{scale, src: data.previewImage!.url}}
width={scale! * width}
className="block object-cover w-full h-full"
data={data}
data={data as MediaVideo}
controls={false}
muted
loop
Expand All @@ -129,7 +131,7 @@ function SpreadMedia({
sizes={sizes}
alt={data.alt || 'Marketing Banner Image'}
className="block object-cover w-full h-full"
data={data.image}
data={(data as MediaImage).image!}
loading={loading}
width={width}
loaderOptions={{scale, crop: 'center'}}
Expand Down
9 changes: 5 additions & 4 deletions app/components/ProductGallery.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type {MediaEdge} from '@shopify/hydrogen-react/storefront-api-types';
import {ATTR_LOADING_EAGER} from '~/lib/const';
import type {MediaImage} from '@shopify/hydrogen-react/storefront-api-types';

/**
* A client component that defines a media gallery for hosting images, 3D models, and videos of products
Expand Down Expand Up @@ -32,7 +33,7 @@ export function ProductGallery({
...med.image,
altText: med.alt || 'Product image',
},
};
} as MediaImage;

switch (med.mediaContentType) {
case 'IMAGE':
Expand Down Expand Up @@ -82,10 +83,10 @@ export function ProductGallery({
key={med.id || med.image.id}
>
{/* TODO: Replace with MediaFile when it's available */}
{med.image && (
{(med as MediaImage).image && (
<img
src={med.image.url}
alt={med.image.altText}
src={data.image!.url}
alt={data.image!.altText!}
className="w-full h-full aspect-square fadeIn object-cover"
/>
)}
Expand Down
5 changes: 4 additions & 1 deletion app/lib/session.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import {

let sessionStorage: SessionStorage;

export async function getSession(request: Request, context: AppLoadContext) {
export async function getSession(
request: Request,
context: AppLoadContext & {env?: Record<string, string>},
) {
if (!context.env?.ENCRYPTION_KEY) {
throw new Error('ENCRYPTION_KEY environment variable is not set');
}
Expand Down
3 changes: 2 additions & 1 deletion app/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import styles from './styles/app.css';
import favicon from '../public/favicon.svg';

export const handle = {
seo: (data) => ({
// @todo - remove any and type the seo callback
seo: (data: any) => ({
title: data.layout.shop.name,
bypassTitleTemplate: true,
titleTemplate: `%s | ${data.layout.shop.name}`,
Expand Down
2 changes: 1 addition & 1 deletion app/routes/$lang/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Everything in the $lang folder is a re-export of the route folder
// Wondering if we can just have it as a build process (dynamically creates these
// files based on the files in the routes folder) during build/hot reload process
export {default, meta, loader} from '~/routes/index';
export {default, loader} from '~/routes/index';
9 changes: 2 additions & 7 deletions app/routes/$lang/journal/$journalHandle.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import Component, {
loader,
meta,
links,
CatchBoundary,
} from '~/routes/journal/$journalHandle';
import Component, {loader, meta, links} from '~/routes/journal/$journalHandle';

export {loader, meta, links, CatchBoundary};
export {loader, meta, links};
export default Component;
8 changes: 2 additions & 6 deletions app/routes/$lang/products/$productHandle.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import Component, {
loader,
action,
ProductForm,
} from '~/routes/products/$productHandle';
import Component, {loader, ProductForm} from '~/routes/products/$productHandle';

export {loader, action, ProductForm};
export {loader, ProductForm};
export default Component;
4 changes: 2 additions & 2 deletions app/routes/account/__private/orders.$id.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ export async function loader({request, context, params}: LoaderArgs) {
throw new Response('Order not found', {status: 404});
}

const lineItems: Array<OrderLineItem> = flattenConnection<OrderLineItem>(
const lineItems = flattenConnection<OrderLineItem>(
order.lineItems!,
);
) as Array<OrderLineItem>;

const discountApplications = flattenConnection<DiscountApplication>(
order.discountApplications as DiscountApplicationConnection,
Expand Down
4 changes: 3 additions & 1 deletion packages/@hydrogen/remix/storefront.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ export type StorefrontClientProps = Parameters<
typeof createStorefrontUtilities
>[0];

export type Storefront = ReturnType<typeof createStorefrontClient>;
export type Storefront = ReturnType<
typeof createStorefrontClient
>['storefront'];

export type HydrogenContext = {
storefront: Storefront;
Expand Down