Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8965851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:53:59+00:00 2026-06-15T16:53:59+00:00

I need a little help with TypeScript . How to do extension methods inheritance?

  • 0

I need a little help with TypeScript. How to do extension methods inheritance?

Lets say we have a class named MyClass with only one method Method1():

class MyClass {
   constructor () { }

   public Method1(): void {
   }
}

Now I want to make a sub class that adds a new method named Method2():

class MyClassExtension {
   public Method2(): void {
   }
}

When I have interfaces I can do this by declaring a new interface with the same name:

interface MyInterface {
   Method1(): void;
}

interface MyInterface {
   Method2(): void;
}

var x: MyInterface;
x.Method1(); // ok
x.Method2(); // ok

But I don’t know how to do this for classes:/ Can any1 help me, please?

Thanks in advance!!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T16:54:00+00:00Added an answer on June 15, 2026 at 4:54 pm

    Based on your response to JohnnyHK’s answer, can you do something like the following?

    If your existing jquery.d.ts looks something like this:

    interface JQuery {
        //...OTHER MEMBERS IN JQUERY
        addClass(classNames: string): JQuery;
        addClass(func: (index: any, currentClass: any) => JQuery);
    
        attr(attributeName: string): string;
        attr(attributeName: string, value: any): JQuery;
        //...OTHER MEMBERS IN JQUERY
    }
    
    interface JQueryStatic {
        //...OTHER MEMBERS IN JQUERY
        parent(selector?: string): JQuery;
    
        parents(selector?: string): JQuery;
    
        parentsUntil(selector?: string, filter?: string): JQuery;
        parentsUntil(element?: Element, filter?: string): JQuery;
        //...OTHER MEMBERS IN JQUERY
    }
    
    
    declare var jQuery: JQueryStatic;
    declare var $: JQueryStatic;
    

    Then all you would need to do in your code somewhere is define your extension methods, for example:

    file1.ts

    ///<reference path='jquery.d.ts'/>
    interface JQuery {
        myNewExtensionMethod() : string;
    }
    interface JQueryStatic {
        myNewExtensionMethod() : string;
    }
    
    jQuery.myNewExtensionMethod = () => {
        return "11";
    }
    
    $.myNewExtensionMethod = () => {
        return "11";
    }
    

    And then use them:

    file2.ts

    ///<reference path='file1.ts'/>
    var result = $.myNewExtensionMethod();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Need a little help with a SQL / ActiveRecord query. Let's say I have
Need a little help again. Say I have an unordered list, and I want
I need little help with inheritance in C++. I have code with same structure
need a little help with this one. I have a form that I am
I need a little help to solve the following question. I have two activities,
I need a little help how to go about doing this. I have created
I need a little help writing a query. I have this data... vDir iNumber
I need a little help converting some VB.NET code to C#. I have tried
I need little help on a homework assignment. I have to create a 10
Need a little help with string formatting... I have a string like this: Bmw

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.