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

The store works in dev mode(yarn dev), but does not compile for production(yarn buld). #352

Open
og-dev opened this issue Aug 3, 2024 · 2 comments

Comments

@og-dev
Copy link

og-dev commented Aug 3, 2024

OS: Ubuntu 20.04
Node: 18.18.0

Fail due Type error: Parameter 'c' implicitly has an 'any' type.

yarn run v1.22.22
$ next build
next.config.js {}
  ▲ Next.js 14.2.5
  - Environments: .env.local

   Creating an optimized production build ...
next.config.js {}
next.config.js {}
next.config.js {}
 ✓ Compiled successfully
   Linting and checking validity of types  ...Failed to compile.

./src/modules/checkout/components/shipping-address/index.tsx:37:39
Type error: Parameter 'c' implicitly has an 'any' type.

  35 |
  36 |   const countriesInRegion = useMemo(
> 37 |     () => cart?.region.countries.map((c) => c.iso_2),
     |                                       ^
  38 |     [cart?.region]
  39 |   )
  40 |
error Command failed with exit code 1.

if strict is disbled in tsconfig then: Linting and checking validity of types ..Failed to compile.

store-storefront# yarn build
yarn run v1.22.22
$ next build
next.config.js {}
  ▲ Next.js 14.2.5
  - Environments: .env.local

   Creating an optimized production build ...
next.config.js {}
next.config.js {}
next.config.js {}
 ✓ Compiled successfully
   Linting and checking validity of types  ..Failed to compile.

./src/app/[countryCode]/(main)/cart/page.tsx:37:3
Type error: Type '"" | "address" | "delivery" | "payment"' is not assignable to type '"address" | "payment" | "delivery"'.

  35 |   }
  36 |
> 37 |   cart.checkout_step = cart && getCheckoutStep(cart)
     |   ^
  38 |
  39 |   return cart
  40 | }
error Command failed with exit code 1.

Is there a way to fix those error?

I tried to fix the second error by changing @types/react, @types/react-dom but it did not work

@anzweidrej
Copy link

anzweidrej commented Aug 5, 2024

Hi @og-dev,

As you already guessed, this is due to the "strict" mode enabled in tsconfig, to solve the error without having to disable the option, you can try the following solutions:

Option 1:

const countriesInRegion = useMemo(
    () => cart?.region.countries.map((c: { iso_2: string }) => c.iso_2),
    [cart?.region]
  )

Option 2:

type CountryProps = {
  iso_2: string;
};

const countriesInRegion = useMemo(
  () => cart?.region.countries.map((c: CountryProps) => c.iso_2),
  [cart?.region]
);

@adambarath
Copy link

I had the same issue. See my comment at: #279 (comment)

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

No branches or pull requests

3 participants