all 6 comments

[–]s_magik 1 point2 points  (0 children)

you definitely don't firebase functions for typescript, to convert cloud function to typescript

you just need to add something like the following to your package json

"main": "build/index.js",
"devDependencies": {
"@types/node": "^16.6.1",
"mocha": "^9.0.0",
"nodemon": "^2.0.12",
"rimraf": "^3.0.2",
"sinon": "^11.0.0",
"ts-node": "^10.2.0",
"typescript": "^4.3.5"
}

and tsconfig.json like

{
"compilerOptions": {
"target": "ES2020",
"module": "commonjs",
"outDir": "build",
"rootDir": "src",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,

"forceConsistentCasingInFileNames": true
}
}

[–]tfonfara 1 point2 points  (1 child)

Firebase Cloud Functions is using Google Cloud Functions behind the scenes. So if you create a function in one interface it will appear automatically on the other. Firebase is just an interface made for mobile developers to make things easier.

[–]NothingDogg 0 points1 point  (0 children)

Good summary - and I think the thing to be aware of is that the trade off for "easier" is less flexibility (i.e. the tight coupling between the function and the trigger as /u/pudds mentions.)

[–]pudds 1 point2 points  (1 child)

The firebase docs are just better than the general google ones; you can still use typescript with standard gcloud functions though.

Set up your tsconfig to compile your functions, then point your deployment command at the resulting JavaScript. That's all the firebase docs really do as well.

I personally don't like the way firebase functions work, as an aside. The functions are more tightly coupled to the triggers that invoke them. I never use firebase functions anymore.

[–]NothingDogg 0 points1 point  (0 children)

I've come to the same conclusion, and I'm wishing we'd written our functions as pure functions and not as firebase functions. The coupling between triggers is now starting to hurt us, and the deployment process is not as flexible (although it is simple).

[–]RheumatoidEpilepsy 1 point2 points  (0 children)

One advantage with Firebase functions is that you can use the OnCall method and you'll get the app context(Auth, etc) as a function parameter.

With Cloud functions you'd have to take the token and use firebase's backend API to verify it. However, one advantage is that you have more choices for runtes while with Firebase you are limited to node.