Skip to content

Commit 1c4d9d7

Browse files
committed
Docs: Added more information on typings usage, see #744
1 parent 602065e commit 1c4d9d7

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

README.md

+5-6
Original file line numberDiff line numberDiff line change
@@ -458,14 +458,16 @@ protobuf.load("awesome.proto", function(err, root) {
458458
console.log(`message = ${JSON.stringify(message)}`);
459459

460460
let buffer = AwesomeMessage.encode(message).finish();
461-
console.log(`buffer = ${Array.prototype.slice.call(buffer)}`);
461+
console.log(`buffer = ${Array.prototype.toString.call(buffer)}`);
462462

463463
let decoded = AwesomeMessage.decode(buffer);
464464
console.log(`decoded = ${JSON.stringify(decoded)}`);
465465
});
466466
```
467467

468-
If you generated static code using the CLI to `bundle.js` and its type definitions to `bundle.d.ts`, then you can do:
468+
**Note:** Dynamically generated runtime message classes cannot be typed, technically, so you must either access its fields using `message["awesomeField"]` notation or you can utilize [typings of its static counterpart](https://github.com/dcodeIO/protobuf.js/tree/master/cli#pbts) for full typings support.
469+
470+
If you generated static code to `bundle.js` using the CLI and its type definitions to `bundle.d.ts` instead, then you can just do:
469471

470472
```ts
471473
import * as root from "./bundle.js";
@@ -477,13 +479,10 @@ var buffer = AwesomeMessage.encode(message).finish();
477479
...
478480
```
479481

480-
**Note:** By default, the npm package ships with long.js including its typings and node typing as optional dependencies. However, where long.js and/or node Buffers are not required, there are two stubs available that can be referenced instead of the full type definitions:
482+
**Note:** When using [long.js](https://github.com/dcodeIO/long.js), make sure to add [@types/long](https://www.npmjs.com/package/@types/long) to your project's dependencies. Likewise, when building for node, make sure to add [@types/node](https://www.npmjs.com/package/@types/node). Alternatively, if you are not using one of these, there are two stubs available that can be referenced instead of the respective full type definition:
481483

482484
```ts
483485
/// <reference path="./node_modules/protobufjs/stub-long.d.ts" />
484-
```
485-
486-
```ts
487486
/// <reference path="./node_modules/protobufjs/stub-node.d.ts" />
488487
```
489488

package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@
5656
"@protobufjs/utf8": "^1.1.0"
5757
},
5858
"optionalDependencies": {
59-
"long": "^3.2.0",
60-
"@types/long": "^3.0.31",
61-
"@types/node": "7.0.12"
59+
"long": "^3.2.0"
6260
},
6361
"devDependencies": {
62+
"@types/long": "^3.0.31",
63+
"@types/node": "7.0.12",
6464
"benchmark": "^2.1.4",
6565
"browserify": "^14.1.0",
6666
"browserify-wrap": "^1.0.2",
@@ -77,7 +77,7 @@
7777
"gulp": "^3.9.1",
7878
"gulp-header": "^1.8.8",
7979
"gulp-if": "^2.0.1",
80-
"gulp-sourcemaps": "^2.5.0",
80+
"gulp-sourcemaps": "^2.5.1",
8181
"gulp-uglify": "^2.1.2",
8282
"istanbul": "^0.4.5",
8383
"jaguarjs-jsdoc": "dcodeIO/jaguarjs-jsdoc",

0 commit comments

Comments
 (0)