Error message TS2339 in Typescript: The property '__super__' is not found on the type '($element: any, options: any) => any'

Having trouble with 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());
        });
    });

An error occurs when running ng build:

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'.

Looking for a solution to this issue. Tried declaring var CustomData: any; and adding /* tslint:disable */ before the class export line.

Answer №1

Did you attempt to convert the CustomData object to type any?

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

Alternatively, you can create a function interface for CustomData (I have not tested this)

Here is a sample of how the function interface could look:

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

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

CustomData.prototype....

You can customize the interface with specific properties and types instead of using any.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Implementing asynchronous image loading with Angular 4 using bearer headers

Currently, I am working on making asynchronous image requests with authentication headers. The image paths in the code look like this: <img src="{{file.src}}"/> I need to include a Bearer Token in the header for these requests, but since there are ...

Issue with Angular2 Router: No routes were found for the specified path ''

I have set up the Angular2 Router in the following way: import { provideRouter, RouterConfig } from '@angular/router'; import { Page2} from './page2'; const routes: RouterConfig = [ { path: 'page2', component: Page2 } ]; ...

Issue with Bootstrap 4 component styling in Angular 4 application test

I am working on creating a test application using Angular 4 and have successfully installed Bootstrap 4 for Angular as instructed on https://ng-bootstrap.github.io/#/getting-started. I have included Bootstrap in the main module and in my basic navbar menu ...

Unable to reference the namespace 'ThemeDefinition' as a valid type within Vuetify

Looking to develop a unique theme for Vuetify v3.0.0-alpha.10 and I'm working with my vuetify.ts plugin file. import "@mdi/font/css/materialdesignicons.css"; import "vuetify/lib/styles/main.sass"; import { createVuetify, ThemeDefinition } from "v ...

Guide on how to update an array within typed angular reactive forms

I'm currently working on finding a solution for patching a form array in a strongly-typed reactive Angular form. I've noticed that patchValue and setValue don't consistently work as expected with FormControl. Here's an example of the fo ...

The modal remains closed: Error - Attempting to access property 'open' of undefined

I've been attempting to showcase a pop-up that I implemented as a modal, but I keep getting this error: TypeError: Cannot read property 'open' of undefined The pop-up was created as a component: import { Component, OnInit, ViewChild, Ele ...

Erase the destination pin on Google Maps

I am currently working on a project that involves displaying hit markers on google maps along with a route from start to finish. Although I have successfully displayed the route, I encountered an issue where both the origin and destination have identical ...

Setting ngModel to the month input control

I am trying to use ngModel to link a date object that contains the current month value and display the month and year on the input month calendar. However, even though the object is successfully bound to the control, the month/year does not appear. Any tip ...

What is the reason behind the occurrence of `(User & { _id: Schema.Types.ObjectId; }) | null` when calling findById?

Today marks my debut using typescript and mongoose. Here's a glimpse of what I've worked on. Type export interface User extends Document { _id: ObjectId; lastName: string; } Schema const userSchema = new Schema<User>({ lastName: { t ...

Angular2 - receiving an error message stating that this.router.navigate does not exist as a

Currently, I am delving into the world of Angular2 with Ionic and working on crafting a login page. However, upon loading the page, an error surfaces: 'router.initialNavigation is not a function' To address this issue, I inserted '{initialN ...

The takeUntil function will cancel an effect request if a relevant action has been dispatched before

When a user chooses an order in my scenario: selectOrder(orderId): void { this.store$.dispatch( selectOrder({orderId}) ); } The order UI component triggers an action to load all associated data: private fetchOrderOnSelectOrder(): void { this.sto ...

How to eliminate file nesting in Visual Studio 2017

Is there a way to prevent certain file types from being nested within other files, such as .ts files not being nested beneath .html files? I came across this request, but has anyone found a solution to achieve this? ...

Issue with login form in IONIC: Form only functions after page is refreshed

Encountering an issue with my Ionic login form where the submit button gets disabled due to invalid form even when it's not, or sometimes displays a console error stating form is invalid along with null inputs. This problem seems to have surfaced afte ...

Navigating through alterations in intricate data utilizing the BehaviorSubject concept

If I have a Service that offers a BehaviorSubject to any component needing the most up-to-date version of certain data, how can these components differentiate what changed in the data when they receive notifications? export class DataService { pri ...

The use of async/await within an observable function

I am looking to establish an observable that can send values to my observers. The issue lies in the fact that these values are acquired through a method that returns a promise. Is it possible to use await within the observable for the promise-returning f ...

Having trouble with npm install on an Angular project? It seems to be failing with an ECONNREFUSED error while trying to

I am facing an issue while trying to clone one of my Angular projects. To make it work, I need to run npm install, which used to work fine in the past. However, recently I encountered the following error: npm install npm ERR! code ECONNREFUSED npm ERR! ...

Understanding Scope in TypeScript

Recently, I developed a sample application in Node.js which utilizes pg-promise to execute queries on a Postgres database. I encapsulated this functionality within a class named PostgresDataAccess. However, I encountered an issue while trying to access t ...

Retrieve the unchanged data from the source before any modifications using ag-Grid

Is the original data saved anywhere when accessing data with the ag-Grid API? For instance, can it be retrieved from: api.getRowNode(id) This information could come in handy, especially if you want to highlight an edited cell by comparing values and chan ...

Incorporate MUX Player (Video) into Angular versions 14 or 15

Mux offers a video API service with its own player: MUX Player I am interested in integrating this npm package specifically into a component in Angular 14/15. The JavaScript should only be loaded when this particular component is rendered. Integration Th ...

The Angular build is unsuccessful due to the presence of components from a separate Angular project

Whenever I execute ng build project1 --prod, the build fails and displays this error message: ERROR in : Cannot determine the module for class MyComponent in .../project2/app/my.component.ts! Add MyComponent to the NgModule to fix it.. Although the sol ...