feat: migrate lib layer to TypeScript#27
Open
devin-ai-integration[bot] wants to merge 1 commit into
Open
Conversation
- Install TypeScript, @types/react, @types/react-dom, @types/node - Remove .babelrc and babel dependencies - Create tsconfig.json with strict mode - Create types/index.ts with SanityProduct, CartItem, SanityBanner interfaces - Create types/canvas-confetti.d.ts declaration file - Rename lib/client.js -> lib/client.ts with SanityClient, SanityImageSource, ImageUrlBuilder types - Rename lib/getStripe.js -> lib/getStripe.ts with Stripe types - Rename lib/utils.js -> lib/utils.ts with proper parameter and return types - Add next-env.d.ts for Next.js TypeScript support Verified: npx tsc --noEmit passes, npm run build succeeds 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:
|
Author
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
Migrates the three utility files in
lib/from JavaScript to TypeScript with proper type annotations, and sets up the TypeScript foundation for the project.TypeScript foundation:
tsconfig.jsonwithstrict: true,allowJs: true(so existing.js/.jsxfiles still compile), andignoreDeprecations: "6.0"(required since TS 6.0 deprecatesmoduleResolution: "node")typescript,@types/react@17.0.39,@types/react-dom@17.0.11,@types/node(pinned@types/reactto 17.x for Next.js 12 compatibility — newer versions useexportsmaps that break Next.js 12'srequire.resolvecheck).babelrcand@babel/core/@babel/preset-react(Next.js SWC handles JSX compilation)types/index.tswith sharedSanityProduct,CartItem,SanityBannerinterfacestypes/canvas-confetti.d.ts(no@types/canvas-confettipackage exists)next-env.d.tsFile migrations:
lib/client.js→lib/client.ts— typedclientasSanityClient,urlForparam asSanityImageSourcewithImageUrlBuilderreturn typelib/getStripe.js→lib/getStripe.ts— typedstripePromiseasPromise<Stripe | null> | undefined, added explicit return typelib/utils.js→lib/utils.ts— added: voidreturn torunFireworks, typedrandomInRangeparams/returnVerified locally:
npx tsc --noEmitpasses,npm run buildsucceeds.Review & Testing Checklist for Human
.babelrcand@babel/core/@babel/preset-reactdoesn't break JSX compilation for the remaining.jsx/.jsfiles (Next.js SWC should handle it, but worth confirming vianpm run buildornpm run dev)getStripe.ts:process.env.NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY!uses!— if the env var is unset,loadStripereceivesundefinedat runtime with no type error. Confirm this is acceptable vs. throwing early.lib/client,lib/getStripe,lib/utils(components/Cart.jsx, pages/success.js, etc.) still resolve correctly after the rename.allowJs: truein tsconfig should handle this, but testnpm run devand navigate through the app.canvas-confettitype declaration: Reviewtypes/canvas-confetti.d.tsfor completeness — it covers the options used inutils.tsbut is not exhaustive.Recommended test plan: Run
npm run dev, navigate the storefront, add an item to cart, and complete the Stripe checkout flow to reach the success page (which triggersrunFireworksfromlib/utils.ts).Notes
@types/reactis pinned to17.0.39because newer patch versions (even within 17.x) add anexportsmap that breaks Next.js 12's internalrequire.resolve('@types/react/index.d.ts')check during build.client.js → client.tsandgetStripe.js → getStripe.tsas renames in the diff (they show as delete+create), thoughgit mvwas used.Link to Devin session: https://app.devin.ai/sessions/8ecd0e1a650240ac8abc2aac14025297
Requested by: @WesternConcrete