Uploaded image for project: 'Thrift'
  1. Thrift
  2. THRIFT-4675

JS code generators not handling int64 type properly for constants and for TypeScript type mappings

    XMLWordPrintableJSON

    Details

      Description

      The code generated for JS constants involving the int64 Thrift type do not rely on the Int64 JS type (from the node-int64 package Thrift uses for handling 64-bit integers).

      For example, consider the following Thrift constant definitions:

          const i64 MAX_INT64 = 9223372036854775807
          const i64 SMALL_INT64 = 15
      

      This results in generating the following code:

      For node.js:

          ttypes.MAX_INT64 = 9223372036854775807;  
          ttypes.SMALL_INT64 = 15;  
      

      For the browser:

          MAX_INT64 = 9223372036854775807;
          SMALL_INT64 = 15;  
      

      Since the JS number type cannot natively represent integers that do not fit into a double precision floating point, this will result in lost precision for certain values. E.g., printing MAX_INT64 would produce 9223372036854776000.

      The correct output should be (showing for node.js):

          ttypes.MAX_INT64 = new Int64(''7FFFFFFFFFFFFFFF'');  
          ttypes.SMALL_INT64 = new Int64(15);  
      

      Besides this, none of the Typescript type bindings (.d.ts files) contain the types for int64 types. This includes constants, types, and service method parameters.

      Note that fixing this may break some of the existing code. In my mind, this is how it should work by default, but I don't know the policy in Thrift regarding backward compatibility. It could also be added as an option.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                jking3 James E. King III
                Reporter:
                bgedik Bu─čra Gedik
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 40m
                  40m