How to implement a Typescript interface without necessarily implementing the parent interfaces

Within my current project, I have defined the following interfaces:

interface foo {
  fooProperty: number;
  fooFunction(): void;
}

interface bar extends foo {
  barProperty: string;
  barFunction(): void;
}

Now, I am interested in creating a class like this:

class myBar implements bar {
  public barProperty: string = "bar";
  public barFunction() {
    // perform some action
  }
}

However, I want to avoid implementing the properties and functions of foo as they are already specified in an existing JS class that is described by the interfaces.

Essentially, I aim to develop a TypeScript class that extends a third-party JS library for which I have ".d.ts" files outlining the implementation details but is not originally written in TypeScript.

In order to utilize a specific function within the third-party library, I need to create a customized class that inherits from a provided JS class using "prototype", but I must accomplish this task using TypeScript.

Update 1

It appears that there may be some confusion regarding my objective, so let me provide further clarification.

Within our project, we make use of a third-party JS library, referred to as "thirdLib.js".

Inside "thirdLib.js", there is functionality that necessitates extending a JS-style class included in "thirdLib.js" in the following manner:

function myClass(){
  thirdlib.thirdclass.call(this);
}

thirdLib.utilities.extendclass(myClass, thirdLib.thirdClass);

myClass.prototype.overriddenFunc = function(){
  // Implement custom function here
}

The "extendClass" method in "thirdlib" copies the constructor of the base class into my constructor, or at least that is my understanding.

Later on, within "thirdlib.js", this extended class is employed somewhere else like so:

var myStuff = new thirdLib();
var theClass = new myClass();

myStuff.registerSomething(theClass);
myStuff.doAThing();

Upon calling "doAThing", the newly registered JS class in "thirdLib.js" possesses all the original functionalities from "thirdClass" along with my customizations.

I only have access to the minified JavaScript code of "thirdLib.js" and a set of self-authored TypeScript definition files. My goal is to construct "myClass()" using standard TypeScript features while inheriting and utilizing the entirety of the original JS class and integrating my additional functionalities into the TS class to override those in the underlying JS class when needed.

Update April 2022

To address any inquiries, approximately six months after my previous comment, I departed from the company associated with this project. Consequently, I do not possess the code or accessibility to it anymore, thus I doubt the matter will reach a resolution. For those intrigued, the "Custom Drawing Handler" I attempted to implement was a personalized drawing class for a previously commercial (now open-source) third-party JS library known as "MXGraph".

Answer №1

It seems like you just need to extend the myFoo class with your myBar class in order to inherit the existing implementation and meet the requirements specified in the interface.

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

Storybook encounters an undefined error with the Vuex store

Here is a snippet from my main.js file: import './plugins'; import store from './store'; import FileUpload from './components/FileUpload'; export default { install(Vue) { Vue.component('file-upload', ...

Deciphering TS2345: "The argument supplied, known as 'typeof MyComponent', cannot be assigned to the specified parameter type"

I am facing an issue while attempting to integrate a Typescript React component with react-onclickoutside. The error message that I encounter is as follows: TS2345: Argument of type 'typeof MyComponent' is not assignable to parameter of type &apo ...

Employing a lexicon of hexadecimal color code values to harmonize CSS styles

I have a unique requirement where I need to utilize a dictionary of HTML color codes and then apply those colors as styles. It's an interesting challenge! Here is an example of how my color dictionary looks like: const colorCodes = { red: ...

Is there a way for me to keep an image stationary on the page while allowing overlaying text to move?

Currently, I am exploring the process of coding a website that mimics the style of this particular webpage: . I am particularly interested in learning how to create a scrolling effect for text within a fixed area, while keeping the accompanying images st ...

Utilizing mapped data to display numerous Material-UI Dialog elements

On my table, I have a list of users displayed. Each user has a button in their row to delete them. Clicking the delete button triggers a Material-UI Dialog to confirm. An issue arises where 3 dialogs are being rendered due to mapping, and the last dialog ...

Is there a discrepancy in the value between data and computed properties in Vue components?

Upon reviewing my code, I have noticed that the value shown in the data of the component does not match the desired value. The code snippet is provided below: View.component('xxx-item',{ props:['item'], template:`xxxx`, computed: ...

Changing the z-index property of a Material-UI <Select> dropdown: What you need to know

Currently, I am implementing an <AppBar> with a significantly high z-index value (using withStyles, it is set to theme.zIndex.modal + 2 which results in 1202). The primary purpose behind this decision is to guarantee that my <Drawer> component ...

Deactivate the checkboxes with varying attributes

My goal is to disable checkboxes with different warehouse locations once a warehouse is selected. For instance, if I select California, I want all checkboxes from other states to be disabled. This should be based on the whseID attribute, but I am strugglin ...

Can you provide tips on how to center the title on the page?

Currently, I am working on codepen.io and have been tasked with creating a paragraph that includes a title. However, my dilemma lies in the fact that I need this title to be center-aligned without directly altering the "x" value. Unfortunately, CSS is not ...

Can we incorporate 'this' in the super() constructor?

While reviewing someone else's code, I came across the following snippet: class foo extends bar { constructor() { super(param1, param2, new certainObject(this, otherParams)); } } The issue with this code is that it generates an error ...

Determine the data type of an individual attribute within a collection of classes

I am working with a series of classes that have a body property defined within them. Here is an example: class Foo { body: {foo: string} constructor(body: Record<string, string>) { this.body = { foo: body.foo } } } class Bar { body: {ba ...

What steps can I take to decrease the padding of this footer?

Is there a way to reduce the height of the footer so it doesn't dominate the screen on both large and small devices? import { Container, Box, Grid } from "@material-ui/core"; const Footer = (props) => { return ( <footer> ...

Tips for accessing elements using document.getElementsByTagName

Greetings and best wishes for the holiday season! I hope everyone is cozy and safe. I need a little help with some code here, as I am fairly new to JavaScript but not entirely new to programming. Despite finding an answer on this site, I am still encounter ...

Change the location of an HTML element within the page structure

Let's consider having 3 elements like this: <h1>Hello</h1> <p>hello</p> <h1>Hello</h1> I am looking to remove the second <h1> as I only want it to appear once on the page. However, I would like to have flexib ...

The p-dialog lacks the proper styling and does not show or hide correctly

I am working on adding a feature where dragging and dropping an event in a calendar triggers a dialog box that requires the user to confirm if they want to postpone the event. However, I ran into an issue where the styling of my p-dialog is not defaulting ...

Angular 2 Issue: Error Message "Cannot bind to 'ngModel'" arises after FormsModule is added to app.module

I've been struggling with the data binding aspect of this tutorial for over a day now. Here's the link to the tutorial: https://angular.io/docs/ts/latest/tutorial/toh-pt1.html The error I keep encountering is: Unhandled Promise rejection: Tem ...

Successfully resolved: Inability to dynamically adjust button color according to its state

Currently I am working on a feature where a button changes color when it is disabled, but also has a custom color when enabled. Here is the code snippet I am using: Despite setting blue text for the button, it remains blue even after becoming disabled. Ho ...

What is the method to effectively conduct a testing procedure for JavaScript files that have been exported using

I have a JavaScript file called "sum.js" which contains a simple function: // sum.js function sum(a, b) { return a + b; } export default { sum }; Now I want to write a test for this file using Jest. Here is my "sum.test.js" file in the same folder: // ...

What is the best approach for finding the xPath of this specific element?

Take a look at this website Link I'm trying to capture the popup message on this site, but I can't seem to find the element for it in the code. Any ideas? ...

Retrieve data from a form on the server side using an Ajax request

I am currently working on submitting form data through an Ajax call. Here is the relevant form code: <form target="_blank" id="addCaseForm" class="form-horizontal col-md-12" action="" method="POST> <div class="form-group"> <labe ...