I`m trying to create my own Typescript dictionary like class, but with some custom methods to use in my code.
I can create the basic dictionary like this:
export interface IDictionary<T> {
[property: string]: T;
};
export class Dictionary<T> implements IDictionary<T> {
[property: string]: T;
constructor() {}
}
and this works great...but... if i try to create a method in this class, such as
export class Dictionary<T> implements IDictionary<T> {
[property: string]: T;
constructor() {}
public getValues(): T[] { // this will give the error
return Object.values(this);
}
}
I get this error:
Property 'getValues' of type '() => T[]' is not assignable to string index type 'T'
.
Is this even possible? If it is, how can I create methods for my class?