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

Generated TypeScript declarations incorrectly references types when there is more than 1 include

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 0.13.0
    • 0.13.0
    • Java - Compiler
    • None
    • Patch

    Description

      When a service or type definition has multiple includes that are referenced in method parameters or responses the TypeScript generator will generated code that will fail to compile with tsc. This is due to "external" types not being referenced from their import; an assumption is made that they are defined the the default ttypes for the service. 


      With the following input

      import "Other.thrift"
      
      struct MyStruct {
           1:Other.OtherType field;
      }
      
      service MyService {
           Other.OtherResponse magic(1:Other.OtherRequest arg)
      }

      The following generated TypeScript declaration is generated with 0.13.0 which will fail to compile with an invocation of "tsc *.d.ts" 

      // foo_types.d.ts
      import other_types = require("./other"); 
      
      declare class MyStruct {
           public field: OtherType; // !!! Compile failure, unknown type OtherType
      }
      
      // foo_service.d.ts
      import other_types = require("./other"); 
      
      class MyService {
           public magic(request: OtherRequest) : Promise<OtherResponse> // !!! Compile failure, unknown type OtherRequest, OtherResponse
      }
      

      The expected output should be:

      // foo_types.d.ts
      import other_types = require("./other"); 
      
      declare class MyStruct {
           public field: other_types.OtherType; 
      }
      
      // foo_service.d.ts
      import other_types = require("./other"); 
      
      class MyService {
           public magic(request: other_types.OtherRequest) : Promise<other_types.OtherResponse> 
      }
      

      I have a fix for this with the following PR https://github.com/apache/thrift/pull/1820

       

      Attachments

        Issue Links

          Activity

            People

              jking3 James E. King III
              pprice Phil Price
              Votes:
              0 Vote for this issue
              Watchers:
              1 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 - 10m
                  10m