0
votes

I have Javascript code inside typescript

$.fn.select2.amd.require([
    'select2/data/array',
    'select2/utils'
    ], function (ArrayData, Utils) {
      /* tslint:disable */
        function CustomData ($element, options) :any {
            CustomData.__super__.constructor.call(this, $element, options);
        }
      /* tslint:enable */
        Utils.Extend(CustomData, ArrayData);

        CustomData.prototype.query = function (params, callback) {
          var result =  ymaps.suggest(params.term).then(function (items) {
          var data = [];
          var output = {
            results : [],
            more : false
          };
            for (var index = 0; index < items.length; ++index) {
                data.push({
                  id: String(items[index]['displayName']),
                  text: items[index]['displayName'],
                })
            }
            output.results = data;
            callback(output);
          });                
        };

        $("#basic").select2({
            width:"100%",
            closeOnSelect:false,
            dataAdapter: CustomData
        });
        $('#basic').on('select2:select', function (e) {
          console.log(e);
          $('span.select2-search.select2-search--dropdown > input').val($("#basic").val());
        });
    });

when i try ng build, it says

ERROR in src/app/car/car-create/car.component.ts(43,28): error TS2339: Property '__super__' does not exist on type '($element: any, options: any) => any'.

How to solve this problem. I tried to declare var CustomData: any; and /* tslint:disable */ before class export line

1

1 Answers

1
votes

have you tried casting the CustomData object to any ?

(<any>CustomData).__super__.someprop...

or you can also give the CustomData a function interface (haven't tried it)

Here is an additional example for the functions interface:

interface CustomDataFN {
    (this: any, $element: any, options: any): any;
    __super__: any;
}

var CustomData: CustomDataFN = <CustomDataFN>function ($element, options): any {
    CustomData.__super__.constructor.call(this, $element, options);
}

CustomData.prototype....

for sure you can declare the interface with custom properties and types I just put in any to prevent compile errors.