Skip to content

Commit b56073c

Browse files
committed
improved comments and instructions
1 parent 4313185 commit b56073c

File tree

2 files changed

+41
-6
lines changed

2 files changed

+41
-6
lines changed

typescript-getting-started/README.md

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,38 @@ across a project and development team. TypeScript offers support for the
2121
latest and evolving JavaScript features like async functions and decorators,
2222
to 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
6394
that and a few other handy shortcuts in [package.json](functions/package.json)
6495

6596
After 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
```

typescript-getting-started/functions/src/index.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ import * as functions from 'firebase-functions'
44
// import * as admin from 'firebase-admin'
55

66

7-
// // Create and Deploy Your First Cloud Functions
8-
// // https://firebase.google.com/docs/functions/write-firebase-functions
9-
//
7+
// Create and Deploy Cloud Function with TypeScript using script that is
8+
// defined in functions/package.json:
9+
// cd functions
10+
// npm run deploy
11+
1012
export let helloWorld = functions.https.onRequest((request, response) => {
1113
response.send("Hello from Firebase!\n\n");
1214
});

0 commit comments

Comments
 (0)