useAgile returns never if you pass (State/undefined) property in Array syntax
bennoinbeta opened this issue · comments
You can test it with the code below.
There 'undefinedOrState' is typeof never but it should be the type (State | undefined)
// https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-1.html
type AgileHookArrayType<T> = {
[K in keyof T]: T[K] extends State<infer U>
? U[]
: T[K] extends undefined
? undefined
: never;
};
class State<ValueType = any>{
public value: ValueType;
constructor(initialValue: ValueType){
this.value = initialValue;
}
}
// --- Testing of keyof ----------
interface Person {
name: string;
age: number;
location: string;
}
type x = keyof "test";
type y = keyof State;
type v = keyof Person;
// -------------------------------
export function useAgile<X extends Array<State | undefined>>(
deps: X | []
): AgileHookArrayType<X> {
return "" as any;
}
const state = new State<string>("text");
const undefinedOrState: State | undefined = Math.random() > 1 ? new State<number>(3) : undefined;
const [test, test2, test3] = useAgile([state, undefined, undefinedOrState]);
close
not a clean fix but it works..
-> change if a better solution got found