I don't know if the question title was sugestive but my problem is, in a constructor I got a rest parameter that must be the keys of an object and I want that, when I call the constructor, it only allows the keys that isn't yet used.
I don't know if it's possible, but if it is, I would be glad if someone can help me whit it.
Some code to ilustrate my problem below:
class MyClass<GenType> {
// With the Utility Type Partial<?> I achieved the behavior of allowing only the keys
// that the object type GenType has, but it still allows that the same key can be passed
// as argument more than once
constructor(...rest: Array<Partial<keyof GenType>>) {
// constructor stuff
}
}
type MyGenericType = {
key1: string,
key2: number,
key3: Array<number>
}
// Here, in the initialization, it allows to insert the same key multiple times, but
// i want it to allow that a key can be passed just once
const myClassObject = new MyClass<MyGenericType>("key1", "key2", "key1");
Bellow an image of the problem in my real code:
Note that it allow to pass the same key more than once and the code sugestion show all the object keys, I want that it didn't allow the same key more than once and the code sugestion only shows the remaining keys
The effect that I want is possible? If yes, how could I achieve it?
Thanks!