Skip to content

Commit

Permalink
Other: With stubs in place, 'number|Long' return values can be just '…
Browse files Browse the repository at this point in the history
…Long' instead, see #718
  • Loading branch information
dcodeIO committed Mar 23, 2017
1 parent 404ba8e commit e1dd1bc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions cli/targets/static.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ function buildFunction(type, functionName, gen, scope) {
push("};");
}

function toJsType(field) {
function toJsType(field, isReturn) {

This comment has been minimized.

Copy link
@tamird

tamird Mar 23, 2017

How is this meant to be used? The generated code still has number|Long because toJsType is never called with two arguments.

This comment has been minimized.

Copy link
@dcodeIO

dcodeIO Mar 23, 2017

Author Member

Not used, actually, and can be removed again. Thought there'd be any return value types, but there aren't. Just properties. Might become an option, like --strict or something.

This comment has been minimized.

Copy link
@tamird

tamird Mar 23, 2017

I thought the idea was to optionally coalesce number|Long to Long, per #718:

The generated type of certain numeric fields is number|Long, which also makes it impossible to chain Long methods; i.e. it becomes necessary to coalesce or cast to Long before being able to use the field value.

This comment has been minimized.

Copy link
@dcodeIO

dcodeIO Mar 23, 2017

Author Member

Yeah, this happens automatically when long.js is not used and stub-long.d.ts is referenced, because Long is just an alias of number now. However, if long.js is used, both Long and number are valid. For the latter case, there could be an option so that it ignores number and strictly requires Long.

This comment has been minimized.

Copy link
@tamird

tamird Mar 23, 2017

Right, the latter is what I had in mind in #718.

switch (field.type) {
case "double":
case "float":
Expand All @@ -265,7 +265,7 @@ function toJsType(field) {
case "sint64":
case "fixed64":
case "sfixed64":
return "number|Long";
return isReturn ? "Long" : "number|Long";
case "bool":
return "boolean";
case "string":
Expand Down
20 changes: 10 additions & 10 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1211,25 +1211,25 @@ export class Reader {
* Reads a varint as a signed 64 bit value.
* @name Reader#int64
* @function
* @returns {Long|number} Value read
* @returns {Long} Value read
*/
public int64(): (Long|number);
public int64(): Long;

/**
* Reads a varint as an unsigned 64 bit value.
* @name Reader#uint64
* @function
* @returns {Long|number} Value read
* @returns {Long} Value read
*/
public uint64(): (Long|number);
public uint64(): Long;

/**
* Reads a zig-zag encoded varint as a signed 64 bit value.
* @name Reader#sint64
* @function
* @returns {Long|number} Value read
* @returns {Long} Value read
*/
public sint64(): (Long|number);
public sint64(): Long;

/**
* Reads a varint as a boolean.
Expand All @@ -1253,17 +1253,17 @@ export class Reader {
* Reads fixed 64 bits.
* @name Reader#fixed64
* @function
* @returns {Long|number} Value read
* @returns {Long} Value read
*/
public fixed64(): (Long|number);
public fixed64(): Long;

/**
* Reads zig-zag encoded fixed 64 bits.
* @name Reader#sfixed64
* @function
* @returns {Long|number} Value read
* @returns {Long} Value read
*/
public sfixed64(): (Long|number);
public sfixed64(): Long;

/**
* Reads a float (32 bit) as a number.
Expand Down
10 changes: 5 additions & 5 deletions src/reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,21 +175,21 @@ function readLongVarint() {
* Reads a varint as a signed 64 bit value.
* @name Reader#int64
* @function
* @returns {Long|number} Value read
* @returns {Long} Value read
*/

/**
* Reads a varint as an unsigned 64 bit value.
* @name Reader#uint64
* @function
* @returns {Long|number} Value read
* @returns {Long} Value read
*/

/**
* Reads a zig-zag encoded varint as a signed 64 bit value.
* @name Reader#sint64
* @function
* @returns {Long|number} Value read
* @returns {Long} Value read
*/

/**
Expand Down Expand Up @@ -250,14 +250,14 @@ function readFixed64(/* this: Reader */) {
* Reads fixed 64 bits.
* @name Reader#fixed64
* @function
* @returns {Long|number} Value read
* @returns {Long} Value read
*/

/**
* Reads zig-zag encoded fixed 64 bits.
* @name Reader#sfixed64
* @function
* @returns {Long|number} Value read
* @returns {Long} Value read
*/

var readFloat = typeof Float32Array !== "undefined"
Expand Down

0 comments on commit e1dd1bc

Please sign in to comment.