Skip to content

Commit

Permalink
Docs: Added information on how to use the stubs to README, see #718
Browse files Browse the repository at this point in the history
  • Loading branch information
dcodeIO committed Mar 23, 2017
1 parent 0bc4a14 commit 3ba3ad7
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 18 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,13 @@ var buffer = AwesomeMessage.encode(message).finish();
...
```

If you'd like to completely exclude long.js and/or node (Buffer) typings, there are two stubs available that can be referenced instead of the full type definitions:

```ts
/// <reference path="node_modules/protobufjs/stub-long.d.ts" />
/// <reference path="node_modules/protobufjs/stub-node.d.ts" />
```

Documentation
-------------

Expand Down
5 changes: 3 additions & 2 deletions stub-long.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// minimal stub for Long instances for reference when not using long.js.
// minimal stub for Long instances for reference when not using long.js,
// i.e. <reference path="node_modules/protobufjs/stub-long.d.ts" />

type Long = LongStub;

interface LongStub {
lo: number,
hi: number,
unsigned: boolean
unsigned?: boolean
}
3 changes: 2 additions & 1 deletion stub-node.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// minimal stub for node types for reference when not using node.
// minimal stub for node types for reference when not using node,
// i.e. <reference path="node_modules/protobufjs/stub-node.d.ts" />

type Buffer = BufferStub;

Expand Down
6 changes: 3 additions & 3 deletions tests/data/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ $root.Message = (function() {
* @type Object
* @property {string} [stringVal] Message stringVal.
* @property {Array.<string>} [stringRepeated] Message stringRepeated.
* @property {number|$protobuf.Long} [uint64Val] Message uint64Val.
* @property {Array.<number|$protobuf.Long>} [uint64Repeated] Message uint64Repeated.
* @property {number|Long} [uint64Val] Message uint64Val.
* @property {Array.<number|Long>} [uint64Repeated] Message uint64Repeated.
* @property {Uint8Array} [bytesVal] Message bytesVal.
* @property {Array.<Uint8Array>} [bytesRepeated] Message bytesRepeated.
* @property {number} [enumVal] Message enumVal.
* @property {Array.<number>} [enumRepeated] Message enumRepeated.
* @property {Object.<string,number|$protobuf.Long>} [int64Map] Message int64Map.
* @property {Object.<string,number|Long>} [int64Map] Message int64Map.
*/

/**
Expand Down
8 changes: 4 additions & 4 deletions tests/data/mapbox/vector_tile.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,9 @@ $root.vector_tile = (function() {
* @property {string} [stringValue] Value stringValue.
* @property {number} [floatValue] Value floatValue.
* @property {number} [doubleValue] Value doubleValue.
* @property {number|$protobuf.Long} [intValue] Value intValue.
* @property {number|$protobuf.Long} [uintValue] Value uintValue.
* @property {number|$protobuf.Long} [sintValue] Value sintValue.
* @property {number|Long} [intValue] Value intValue.
* @property {number|Long} [uintValue] Value uintValue.
* @property {number|Long} [sintValue] Value sintValue.
* @property {boolean} [boolValue] Value boolValue.
*/

Expand Down Expand Up @@ -534,7 +534,7 @@ $root.vector_tile = (function() {
* Properties of a Feature.
* @typedef vector_tile.Tile.Feature$Properties
* @type Object
* @property {number|$protobuf.Long} [id] Feature id.
* @property {number|Long} [id] Feature id.
* @property {Array.<number>} [tags] Feature tags.
* @property {*} [type] Feature type.
* @property {Array.<number>} [geometry] Feature geometry.
Expand Down
8 changes: 4 additions & 4 deletions tests/data/test.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ export namespace jspb {
type DefaultValues$Properties = {
stringField?: string;
boolField?: boolean;
intField?: (number|$protobuf.Long);
intField?: (number|Long);
enumField?: number;
emptyField?: string;
bytesField?: Uint8Array;
Expand Down Expand Up @@ -597,7 +597,7 @@ export namespace jspb {
type TestMapFieldsNoBinary$Properties = {
mapStringString?: { [k: string]: string };
mapStringInt32?: { [k: string]: number };
mapStringInt64?: { [k: string]: (number|$protobuf.Long) };
mapStringInt64?: { [k: string]: (number|Long) };
mapStringBool?: { [k: string]: boolean };
mapStringDouble?: { [k: string]: number };
mapStringEnum?: { [k: string]: number };
Expand Down Expand Up @@ -1218,8 +1218,8 @@ export namespace google {
type UninterpretedOption$Properties = {
name?: google.protobuf.UninterpretedOption.NamePart[];
identifierValue?: string;
positiveIntValue?: (number|$protobuf.Long);
negativeIntValue?: (number|$protobuf.Long);
positiveIntValue?: (number|Long);
negativeIntValue?: (number|Long);
doubleValue?: number;
stringValue?: Uint8Array;
aggregateValue?: string;
Expand Down
8 changes: 4 additions & 4 deletions tests/data/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2891,7 +2891,7 @@ $root.jspb = (function() {
* @type Object
* @property {string} [stringField] DefaultValues stringField.
* @property {boolean} [boolField] DefaultValues boolField.
* @property {number|$protobuf.Long} [intField] DefaultValues intField.
* @property {number|Long} [intField] DefaultValues intField.
* @property {number} [enumField] DefaultValues enumField.
* @property {string} [emptyField] DefaultValues emptyField.
* @property {Uint8Array} [bytesField] DefaultValues bytesField.
Expand Down Expand Up @@ -5905,7 +5905,7 @@ $root.jspb = (function() {
* @type Object
* @property {Object.<string,string>} [mapStringString] TestMapFieldsNoBinary mapStringString.
* @property {Object.<string,number>} [mapStringInt32] TestMapFieldsNoBinary mapStringInt32.
* @property {Object.<string,number|$protobuf.Long>} [mapStringInt64] TestMapFieldsNoBinary mapStringInt64.
* @property {Object.<string,number|Long>} [mapStringInt64] TestMapFieldsNoBinary mapStringInt64.
* @property {Object.<string,boolean>} [mapStringBool] TestMapFieldsNoBinary mapStringBool.
* @property {Object.<string,number>} [mapStringDouble] TestMapFieldsNoBinary mapStringDouble.
* @property {Object.<string,number>} [mapStringEnum] TestMapFieldsNoBinary mapStringEnum.
Expand Down Expand Up @@ -12463,8 +12463,8 @@ $root.google = (function() {
* @type Object
* @property {Array.<google.protobuf.UninterpretedOption.NamePart>} [name] UninterpretedOption name.
* @property {string} [identifierValue] UninterpretedOption identifierValue.
* @property {number|$protobuf.Long} [positiveIntValue] UninterpretedOption positiveIntValue.
* @property {number|$protobuf.Long} [negativeIntValue] UninterpretedOption negativeIntValue.
* @property {number|Long} [positiveIntValue] UninterpretedOption positiveIntValue.
* @property {number|Long} [negativeIntValue] UninterpretedOption negativeIntValue.
* @property {number} [doubleValue] UninterpretedOption doubleValue.
* @property {Uint8Array} [stringValue] UninterpretedOption stringValue.
* @property {string} [aggregateValue] UninterpretedOption aggregateValue.
Expand Down

0 comments on commit 3ba3ad7

Please sign in to comment.