From 1c4d9d7f024bfa096ddc24aabbdf39211ed8637a Mon Sep 17 00:00:00 2001 From: dcodeIO Date: Tue, 4 Apr 2017 08:53:58 +0200 Subject: [PATCH] Docs: Added more information on typings usage, see #744 --- README.md | 11 +++++------ package.json | 8 ++++---- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 5485315c4..6f784f0cd 100644 --- a/README.md +++ b/README.md @@ -458,14 +458,16 @@ protobuf.load("awesome.proto", function(err, root) { console.log(`message = ${JSON.stringify(message)}`); let buffer = AwesomeMessage.encode(message).finish(); - console.log(`buffer = ${Array.prototype.slice.call(buffer)}`); + console.log(`buffer = ${Array.prototype.toString.call(buffer)}`); let decoded = AwesomeMessage.decode(buffer); console.log(`decoded = ${JSON.stringify(decoded)}`); }); ``` -If you generated static code using the CLI to `bundle.js` and its type definitions to `bundle.d.ts`, then you can do: +**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. + +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: ```ts import * as root from "./bundle.js"; @@ -477,13 +479,10 @@ var buffer = AwesomeMessage.encode(message).finish(); ... ``` -**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: +**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: ```ts /// -``` - -```ts /// ``` diff --git a/package.json b/package.json index a358145c2..ecd21fffd 100644 --- a/package.json +++ b/package.json @@ -56,11 +56,11 @@ "@protobufjs/utf8": "^1.1.0" }, "optionalDependencies": { - "long": "^3.2.0", - "@types/long": "^3.0.31", - "@types/node": "7.0.12" + "long": "^3.2.0" }, "devDependencies": { + "@types/long": "^3.0.31", + "@types/node": "7.0.12", "benchmark": "^2.1.4", "browserify": "^14.1.0", "browserify-wrap": "^1.0.2", @@ -77,7 +77,7 @@ "gulp": "^3.9.1", "gulp-header": "^1.8.8", "gulp-if": "^2.0.1", - "gulp-sourcemaps": "^2.5.0", + "gulp-sourcemaps": "^2.5.1", "gulp-uglify": "^2.1.2", "istanbul": "^0.4.5", "jaguarjs-jsdoc": "dcodeIO/jaguarjs-jsdoc",