Inheritance within classes is ineffective

Currently facing an issue with building an Icon component that should inherit properties from a base class. Strangely, upon instantiation of the Icon, none of the properties from super are present, and the __proto__ property is not properly set.

Despite running a simplified version of the code on CodePen where it works as expected: CodePen Example

The problem arises within Angular 2 context, as the inherited property turns out to always be undefined.

BaseComponent.ts

export abstract class BaseComponent {
  constructor() {
    this.baseImagePath = '/Assets/Images';
  }

  baseImagePath: string;
}

Icon.ts

import {Component, Input} from 'angular2/core';
import {BaseComponent} from '../baseComponent';

@Component({
  selector: 'lib-icon',
  templateUrl: 'app/components/icon/icon.tmpl.html'
})
export class Icon extends BaseComponent {
  @Input() icon: string;

  constructor() {
    super();
    this.baseImagePath += '/icons/';
  }


  getSrc() {
    return `${this.baseImagePath}${this.icon}`;
  }
}

Even after attempting to move the line this.baseImagePath += '/icons/' into ngOnInit just in case - the issue persists with the value remaining undefined.

If you have any insight on what I may be overlooking, your assistance would be greatly appreciated.

Answer №1

Sorry for the unexpected detour into the coding maze. After spending half an hour digging through the code, it turns out that BaseComponent.ts just wasn't compiling for some reason. A few runs of tsc later and everything miraculously fell into place.

Grateful for all the assistance from everyone!

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

Using `new Date(device.timestamp).toLocaleString()` in React with typescript results in an invalid date

The timestamp I am receiving is in unix time format. {devices.map((device, index) => { return ( <tr key={index} className="bg-white border-b "> <td className="py-4 px-6"> {getSensor ...

Show information from a chart depending on the data retrieved from an API request

I am currently learning how to use React and incorporating a store into my application. My goal is to have 2 components, one main component and a child component. The main component will make an API call to retrieve data, which will then be passed to the c ...

Unlocking the Power of Passing Props to {children} in React Components

Looking to create a reusable input element in React. React version: "react": "17.0.2" Need to pass htmlFor in the label and use it in the children's id property. Attempting to pass props to {children} in react. Previously attempte ...

How to Include a JavaScript Library without Export in Angular 2.0.0 using Angular CLI and Webpack

In my Angular 2.0.0 project, I use Angular CLI and Webpack for building. I'm looking to incorporate a JS library (specifically xmltojson.js from https://www.npmjs.com/package/xmltojson) that contains a variable (xmlToJSON) referencing a function. Thi ...

Tips for Fixing the 'Maximum Call Stack Exceeded' Issue with 'useClient' in Component

I'm currently working on developing a Next.js application, and I've encountered a problem while trying to implement the useClient hook in one of my components. Whenever I include the useClient hook in my component, I end up receiving a "Maximum c ...

TS2347: Type arguments cannot be used with untyped function calls

In my bar.ts file, I have the following declarations: declare var angular:any; declare var _:any; declare var $:any; declare var moment:any; declare var ng:any; declare var require:any; And in my bootstrap.ts file, I reference the necessary typings: /// ...

Utilizing the functionalities provided by node.js, I came across an issue and sought out a solution for the error message "TypeError: __WEBPACK_IMPORTED_MODULE_3_fs__.writeFile is not a function"

I have created a project centered around {typescript, react, electron, gaea-editor}. During an event, I utilized fs.writeFile() but encountered an error. The specific error message was: TypeError: __WEBPACK_IMPORTED_MODULE_3_fs__.writeFile is not a functi ...

The Angular Material error message is indicating that the function registerInput is not defined for this._chipList, causing

Issue Description Currently, I am encountering an error when attempting to retrieve input from an <input> tag and showcase it as chips in the graphical user interface (GUI). The console displays the following error message: "TypeError: this._chipLis ...

ngxs combined with Angular version 5.5

During my attempt to install and configure ngxs, I encountered several issues. Upon comparing my package.json file with the one provided on the ngxs GitHub master branch, I noticed that most of the installations were at version 6+. The error message I rece ...

Converting TypeScript to ES5 in Angular 2: A Comprehensive Guide

I am currently diving into Angular 2 and delving into Typescript to create simple applications within the Angular 2 framework. What I have discovered is that with Typescript, we can utilize classes, interfaces, modules, and more to enhance our application ...

Having trouble setting the function props type for its child in Typescript? Getting an error that says "Property 'children' does not exist on type TS2339"?

To provide context, my development environment includes React version 16.9.0 and Typescript version 3.5.3. To replicate the issue, you can install Create React App and create a Typescript project, then add this minimal example: import React from 'rea ...

Unable to upload the image file

I am looking for a way to upload and save single or multiple images using Angular, Node.js, and Mongoose (GridFS). While Base64 encoding is an option, I specifically want to work with GridFS. This implementation is using Angular 7. However, in the backen ...

DiscordJS bot using Typescript experiences audio playback issues that halt after a short period of time

I am currently experiencing difficulties with playing audio through a discord bot that I created. The bot is designed to download a song from YouTube using ytdl-core and then play it, but for some reason, the song stops after a few seconds of playing. Bel ...

Unable to retrieve values from input fields that have been established using interpolation

I'm currently developing a straightforward app that involves a form with formArray. Within the formArray, users can select a product name and amount. Once both are chosen, a third input field - total - computes the total price of the items (product pr ...

typescript method searching for and merging all keys starting with the specified prefix

Take a look at this object: https://i.sstatic.net/V0xvI.png Where each property in system(1) holds tridimensional coordinates. Is there a more efficient method to consolidate properties with the same prefix without nesting loops within loops? My goal is ...

How can you update state with useState in React and perform additional actions in an onChange event?

I'm facing an issue with a component that includes another component (from headlessui/react) defined like this: export default function MyComponent(props) { const [selectedState, setState] = useState(''); return ( <div> & ...

The modification in Typescript's type order from version 1.7 to 1.8 resulted in a significant

A Visual Studio Cordova application with a unique TypeScript source structure: /src /app /appsub1 appsub1.ts -> 4 : 7 /appsub2 appsub2.ts -> 5 : 6 app.ts -> 3 : 5 /mod1 /mod1sub1 mod1sub1.ts -> 7 : 4 m ...

The impact on performance when utilizing object literals within a component template for ng-template context with ngTemplateOutlet in Angular

When passing context to ng-template, what are the performance implications of using an object literal in the template? <ng-container *ngTemplateOutlet="template;context:{ field: value };"></ng-container> as opposed to: <ng-container *ngTe ...

Step-by-step guide on invoking an asynchronous method in canActivate for Ionic and Angular

My objective is to acquire a token for authenticating users. I am utilizing the import { Storage } from '@ionic/storage-angular'; to store the data, but I am encountering an issue where the Storage methods only function in asynchronous mode. Her ...

Prevent Promise / Property not found error in Angular2 by Instantiating Class

When working with my "export class", I encountered an issue that led to a Promise error if I didn't include this line of code: purchase = new Purchase(); right before the constructor. The error indicated that the property "name" was not found. Alth ...