I am writing a validator class, something like
class Validator {
private path: string;
private data: unknown;
constructor(path: string, data: string) {
this.data = data;
this.path = path;
}
public isString() { /* ... */ }
}
Right now my data is of type unknown, but I'd like type to be inherited from constructor i.e.
const validator = new Validator("HomePage", 123); // data in class should be inherited as number
with functions I usually did something like
function<T>(path: string, data: T) { }
But I am unable to figure out how to do it with classes. In particular inheriting from constructor