feat: finalize TypeScript migration — strict mode and linting#30
Open
devin-ai-integration[bot] wants to merge 2 commits into
Open
feat: finalize TypeScript migration — strict mode and linting#30devin-ai-integration[bot] wants to merge 2 commits into
devin-ai-integration[bot] wants to merge 2 commits into
Conversation
- Migrate all JS/JSX files to TS/TSX across lib/, context/, components/, pages/ - Create types/index.ts with SanityProduct, CartItem, SanityBanner interfaces - Add tsconfig.json with strict: true and allowJs: false - Install and configure @typescript-eslint/parser and @typescript-eslint/eslint-plugin - Update .eslintrc.json with TypeScript parser config - Add @babel/preset-typescript to .babelrc for build compatibility - Remove stale yarn.lock, standardize on npm with package-lock.json - All verifications pass: tsc --noEmit (0 errors), npm run build, npm run lint, npm run dev Co-Authored-By: Wes Convery <2wconvery@gmail.com>
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Address Devin Review feedback — conditionally render HeroBanner and FooterBanner only when bannerData is non-empty instead of using an unsafe type assertion that would cause runtime crashes. Co-Authored-By: Wes Convery <2wconvery@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Complete JS-to-TS migration of the entire Next.js 12 ecommerce app. Every source file in
lib/,context/,components/,pages/, andpages/api/has been renamed from.js/.jsxto.ts/.tsxwith full strict-mode type annotations.Key changes:
tsconfig.json: Created with"strict": true,"allowJs": false; includes"ignoreDeprecations": "6.0"because Next.js 12 forcesmoduleResolution: nodewhich TS 6.0 deprecates.types/index.ts: Shared interfaces (SanityProduct,CartItem,SanityBanner,StateContextType) inferred from usage patterns in the codebase (not from a Sanity schema file)..babelrc: Added@babel/preset-typescript— required because the project uses a custom Babel config that disables SWC, so Babel must understand TS syntax..eslintrc.json: Extended with@typescript-eslint/recommended, parser, and plugin.yarn.lockremoved: Standardized onnpm/package-lock.jsonsince all dependency changes were made via npm. The staleyarn.lockwas causing Next.js 12's type-check step to fail.@types/react@17.0.39: Pinned to this specific older version for compatibility with Node.js 22 + Next.js 12'srequire.resolvepackage detection.Incidental bug fixes made during migration
These were discovered because strict TS caught them or because the original code had runtime issues:
index.tsx(HeroBanner/FooterBanner){} as SanityBannerfallbackbannerDatais empty — the previous cast silenced TS but passed an empty object that would throw on property accessCart.tsx:27response.statusCode→response.statusfetchResponse uses.status, not.statusCodeCart.tsx:32stripe.redirectToCheckout(…)→stripe?.redirectToCheckout(…)getStripe()can returnnullCart.tsx:78onClick=""from quantity<span>StateContext.tsxonAddreturn cartProductin.map()else-branchundefinedfor non-matching itemsStateContext.tsxonAddproduct.quantity = quantity→ spread{ ...product, quantity }StateContext.tsxonRemovefoundProducturlFor(x)→urlFor(x).url()Review & Testing Checklist for Human
SanityProduct,CartItem, andSanityBannerintypes/index.tswere inferred from code usage, not from a Sanity schema. Fields likeSanityImage.asset._ref,SanitySlug, and all banner fields should be cross-checked against the actual Sanity studio schema.StateContext.tsx: TheonAddmap fix (addingreturn cartProduct) and the spread-instead-of-mutate change alter runtime behavior — confirm cart add/update still works correctly.urlFor(...).url()renders images correctly: EveryurlFor()call now chains.url(). Verify images load on the homepage, product pages, and cart.yarn.lockremoval: If your team usesyarn, this may be unwanted. The removal was necessary because the stale lockfile brokenext build's type detection.pages/api/stripe.ts:'2020-08-27' as Stripe.LatestApiVersionis a type assertion that papers over a version mismatch — verify this is acceptable for your Stripe integration.Recommended test plan: Run
npm run dev, visit the homepage, open a product detail page, add items to cart, and attempt checkout to verify the migration didn't break any runtime behavior.Notes
@typescript-eslintis pinned to v5.x for compatibility with the project's ESLint 8.13.npx tsc --noEmit(0 errors),npm run build(success),npm run lint(success, warnings only),npm run dev(starts cleanly).Link to Devin session: https://app.devin.ai/sessions/b5bb27e2f3644a37b6945e3b242e9b3e
Requested by: @WesternConcrete