0
abstract class Filter<T> { 

    protected filter = new Map<T>();

}

I get this error message:

No overload expects 1 type arguments, but overloads do exist that expect either 0 or 2 type arguments

Why?

TypeScript 3.9.2

Full abstract class with all methods:

abstract class Filter<K, T> { 

    protected filterModel = new Map<K, T>();

    constructor(protected array: any, private model: T[]) {}

    abstract filter(): void;

    reset(): void { 
        this.filterModel.clear();
    }

    set(item: T) {
        this.filterModel.set("sss", item);
    }

    get(): T[] { 
        return this.model;
    }
}

Problem is in line: this.filterModel.set("sss", item);

Using is:

class FilterByOrderStatus extends Filter<string, FilterOrderStatus> { 

}

So, I try to fill filter model

1 Answers1

0

You have to specify types for both key and value:

abstract class Filter<K, V> { 

    protected filter = new Map<K, V>();

}

See this related SO for more information

slesh
  • 1,902
  • 1
  • 18
  • 29
  • Thank you, how to set generic value then in abstarct class? ` set(item: T) { this.filterModel.set(item.type, item) }` I mean typescript does not understan that property type is present in item. Also Ikey can be different, not only type –  Jun 15 '20 at 21:26