Can we use typescript to write firebase functions at the moment? I saw that we can per https://youtu.be/GNR9El3XWYo?t=13m46s but I am not sure how to configure it.
If we can use typescript can you please provide an example.
Thanks
Hey Tom,
Absolutely! We created the SDK in typescript, so writing functions in Typescript is a great idea since you'll be able to make use of auto-suggestions and compiler errors when using an IDE. When you run npm install --save firebase-functions, the SDK that is downloaded automatically works for both JavaScript and TypeScript development, no additional configuration needed. To get started, import the SDK at the top of index.ts:
import * as functions from 'firebase-functions'
You can then access all of the namespaces and typings under the "functions" top-level name. Refer to our reference docs for all of the typings: https://firebase.google.com/docs/reference/functions/.
You would need to compile the typescript file to a javascript file prior to deploying.
Let me know if that answers your question.
I didn't realise I needed to compile before deploying.
Thanks very much for your help :)
Not a problem!
How can I convert the Typescript code to js, I mean what is good approach for it...is the Typescript also deployed ?
Hey @vitaly87 there are different options, here's a good introduction: https://hackernoon.com/configuring-typescript-compiler-a84ed8f87e3. Everything inside the functions folder is deployed except for the node_modules folder. But only the index.js file is executed, you can reconfigure a main file through the main field of functions/package.json. You can see the source code from our Google I/O functions & machine learning demo to see an example of how you might set up package.json and tsconfig.json. If you have any more questions about writing functions in TypeScript, please post to StackOverflow. That's the best place for usage questions.
Most helpful comment
Hey Tom,
Absolutely! We created the SDK in typescript, so writing functions in Typescript is a great idea since you'll be able to make use of auto-suggestions and compiler errors when using an IDE. When you run
npm install --save firebase-functions, the SDK that is downloaded automatically works for both JavaScript and TypeScript development, no additional configuration needed. To get started, import the SDK at the top of index.ts:import * as functions from 'firebase-functions'You can then access all of the namespaces and typings under the "functions" top-level name. Refer to our reference docs for all of the typings: https://firebase.google.com/docs/reference/functions/.
You would need to compile the typescript file to a javascript file prior to deploying.
Let me know if that answers your question.