@@ -21,7 +21,38 @@ across a project and development team. TypeScript offers support for the
2121latest and evolving JavaScript features like async functions and decorators,
2222to help build robust components.
2323
24- If you are new to TypeScript, check out the [ TypeScript PlayGround] ( https://www.typescriptlang.org/play/index.html ) .
24+ For a nice intro to TypeScript, check out the [ TypeScript PlayGround] ( https://www.typescriptlang.org/play/index.html ) .
25+
26+ ### What is different about TypeScript in this example?
27+
28+ The TypeScript source is in ` functions/src ` and then we need to do a build
29+ step before deploying (see steps below). The main Cloud Function entry
30+ point is ` src/index.ts ` which compiled to ` src/index.js ` and that is specified
31+ in ` functions/package.json ` .
32+
33+ There are two key differences to the example Cloud Function:
34+
35+ * ` require ` -> ` import `
36+ * ` exports. ` -> ` export let `
37+
38+ JavaScript:
39+ ```
40+ var functions = require('firebase-functions');
41+
42+ exports.helloWorld = functions.https.onRequest((request, response) => {
43+ response.send("Hello from Firebase!\n\n");
44+ });
45+ ```
46+
47+ TypeScript:
48+ ```
49+ import * as functions from 'firebase-functions'
50+
51+ export let helloWorld = functions.https.onRequest((request, response) => {
52+ response.send("Hello from Firebase!\n\n");
53+ });
54+ ```
55+
2556
2657
2758### Project Setup
@@ -63,7 +94,9 @@ deploying, so there's an npm script that does the steps. You can see
6394that and a few other handy shortcuts in [ package.json] ( functions/package.json )
6495
6596After the deploy is complete, you will see output with the URL of your
66- Cloud Function endpoint. You can test the function with curl.
97+ Cloud Function endpoint. You can test the function with curl. The following
98+ command will work with any project, since the output of ` firebase use ` is
99+ the current project ID:
67100```
68- curl https://us-central1-YOUR-PROJECT-NAME .cloudfunctions.net/helloWorld
101+ curl https://us-central1-$(firebase use) .cloudfunctions.net/helloWorld
69102```
0 commit comments