feat: migrate API routes to TypeScript#25
Open
devin-ai-integration[bot] wants to merge 1 commit into
Open
Conversation
- Set up TypeScript foundation (tsconfig.json, types/index.ts) - Remove .babelrc and babel dependencies - Install typescript, @types/react, @types/react-dom, @types/node - Rename pages/api/hello.js -> hello.ts with NextApiRequest/NextApiResponse types - Rename pages/api/stripe.js -> stripe.ts with full type annotations - Type handler params (NextApiRequest, NextApiResponse) - Type cart item in req.body.map() with CartItemBody interface - Type params as Stripe.Checkout.SessionCreateParams - Type catch clause error properly 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
Testing ResultsRan dev server locally and tested all migrated API routes end-to-end. API Route Tests (4/4 passed)
Evidence/api/helloHomepage (Babel removal regression check)/api/stripe shell output |
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
pages/api/hello.jsandpages/api/stripe.jsfrom JavaScript to TypeScript, and sets up the TypeScript foundation for the project.TypeScript setup:
tsconfig.jsonwithstrict: true,allowJs: true(to coexist with remaining JS files)next-env.d.ts(auto-generated by Next.js)types/index.ts(SanityProduct,CartItem,SanityBanner)typescript,@types/react@17.0.39,@types/react-dom@17.0.11,@types/nodeBabel removal:
.babelrcand uninstalled@babel/core+@babel/preset-react— Next.js 12's built-in SWC compiler handles JSX transformationAPI route migrations:
hello.ts: AddedNextApiRequest/NextApiResponsetyping to handlerstripe.ts: Typed handler params, addedCartItemBodyinterface forreq.body.map(), typedparamsasStripe.Checkout.SessionCreateParams, typed error in catch blockReview & Testing Checklist for Human
apiVersionchange: The original JS code callednew Stripe(key)without an API version. The TS migration now explicitly passes{ apiVersion: '2020-08-27' }(required by the Stripe v8 types). Verify this matches the version your Stripe account expects — if your account uses a different default API version, this could subtly change Stripe API behavior..babelrcand Babel packages are removed in favor of Next.js SWC. If any other part of the build pipeline or tooling relied on Babel, this could break. Run the full app locally and test checkout flow end-to-end.NEXT_PUBLIC_STRIPE_SECRET_KEY!non-null assertion: The env var access uses!— the app will throw at runtime if this var is missing. Consider whether a startup check or fallback would be safer.CartItemBodyvsCartItem:stripe.tsdefines its ownCartItemBodyinterface rather than reusingCartItemfromtypes/index.ts. The shapes differ (CartItemBody.imageis typed as{ asset: { _ref: string } }[]whileCartItem.imageisany[]). VerifyCartItemBodymatches what the frontend actually sends in the request body.Recommended test plan: Start the dev server, add items to cart, complete a Stripe checkout flow, and confirm the
/api/stripeendpoint still creates sessions correctly.Notes
@types/reactis pinned to17.0.39because newer 17.x patches added anexportsfield that breaks Next.js 12'srequire.resolve('@types/react/index.d.ts')check during build.tsconfig.jsonincludes"ignoreDeprecations": "6.0"becausetypescript@6.0.3deprecatesmoduleResolution: "node".npx tsc --noEmitandnpm run buildboth pass cleanly.Link to Devin session: https://app.devin.ai/sessions/2aff6d8e68fb4c6fb96f729410bec23d
Requested by: @WesternConcrete