agile-ts / agile

🌌 Global State and Logic Library for JavaScript/Typescript applications

Home Page:https://agile-ts.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

useAgile returns never if you pass (State/undefined) property in Array syntax

bennoinbeta opened this issue · comments

commented

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]);
commented

close

commented

not a clean fix but it works..
-> change if a better solution got found