I’ll be honest - I’ve been putting this off for a while. The Firebase Functions v1 to v2 migration has been sitting in my backlog since its announcement, and like many developers, I kept thinking “well, if it’s not broken…”. But after diving into some new features in v2, I realized it was time to bite the bullet and modernize.

Why TypeScript?

The decision to rewrite in TypeScript wasn’t just about following trends. The v2 SDK is written in TypeScript, and the type safety it provides is particularly valuable when dealing with cloud functions. No more scratching your head wondering what properties are available in that data object - TypeScript tells you right there in your editor.

The Migration Process

The first step was simple - updating the dependencies. But anyone who’s done this kind of migration knows that’s the easy part. The real work came with adapting to the new programming model. V2 introduces a more modular approach to function definition, which actually made my code more organized, but required some rethinking of the architecture.

// Old v1 style
exports.myFunction = functions.https.onRequest((req, res) => {
  // function code
});

// New v2 style
export const myFunction = onRequest((req, res) => {
  // Much cleaner!
});

Lessons Learned

  1. The new modular syntax is much cleaner
  2. TypeScript integration is worth the initial setup time
  3. Better error handling with proper types
  4. Improved local testing capabilities

What’s Next

Now that the backend is running on v2 with TypeScript, we have a more maintainable codebase that’s easier to debug and extend. The migration might have been overdue, but sometimes you need that push to modernize your stack.

If you’re still running v1 functions, I’d recommend planning your migration sooner rather than later. The improved developer experience alone makes it worthwhile.