0
I am trying to export a specific class of a module, so far so it is all right. I declared my class as Abstract not to need initialize it with the new, but when trying to use the function "getaway()" the compiler returns me the following error:
TS2339: Property 'getItem' does not exist on type 'typeof Webstorage'
MODULUS:
interface IStorage {
setItem(key : string, value: any) : void;
getItem(key : string) : any;
getItem(key : string) : any;
}
export abstract class WebLocalStorage implements IStorage {
public setItem(key : string, value : any) {
localStorage.setItem(key, value);
}
public getItem(key : string) : any {
localStorage.getItem(key);
}
}
export abstract class WebStorage implements IStorage {
public setItem(key : string, value : any) {
sessionStorage.setItem(key, value);
}
public getItem(key : string) : any {
sessionStorage.getItem(key);
}
}
PLACE WHERE THE MODULE IS BEING IMPORTED:
import { WebStorage } from '../../HTMLAPIS/WebStorageAPI';
export default class FilterData {
private readonly _typingValue: HTMLInputElement;
private readonly _containerMain: HTMLElement;
private readonly _listboxMain: HTMLElement;
private readonly _listboxSecondary: HTMLElement;
constructor(public typingValue: HTMLInputElement, public containerMain : HTMLElement, public listboxMain : HTMLElement, public listboxSecondary : HTMLElement) {
this._typingValue = typingValue;
this._containerMain = containerMain;
this._listboxMain = listboxMain;
this._listboxSecondary = listboxSecondary;
}
public initComponent() {
this.keypress();
}
private keypress() {
this._typingValue.addEventListener('keypress', (e) => {
console.log(WebStorage.getItem('shopkeepers_names'));
});
}
searchData() {
}
}
The problem with this is that the compiler will complain on behalf of the INTERFACE!
– user109930
Oh yes. But if your interface says that the methods cannot be static, then there is no way you can use them without creating an object. You can change the method declaration in the interface, or create different methods in the classes that implement it. If you could contradict the rule you created, which would serve the rule?
– Andre