Alen.Toma
Alen.Toma

Reputation: 4870

how to create keyof of multiType with string appender

I am having trouble with building keyof with mutitype

See below to know the issue

export type NonFunctionPropertyNames<T> = { [K in keyof T]: T[K] extends Function ? never : K }[keyof T];

export type JoinNoneFunctionPropertyNames<T extends object, B extends object, D extends string> =  {
[Key in keyof (T & B) & ( string | number)]: (T & B)[Key] extends Function ? never : (T & B)[Key] extends object 
  ? `${D}.${Key}`
  : `${D}.${Key}`
  }[keyof (T & B) & (string | number)];
  

export interface IQuery<T extends object, D extends string, kType> {
Column: (columnName: kType) => IQuery<T, D, kType>;
InnerJoin: <B extends object>(tableName: D, columnNameA: kType | kType[], columnNameB: NonFunctionPropertyNames<B> | NonFunctionPropertyNames<B>[]) => IQuery<T & B, D, JoinNoneFunctionPropertyNames<T, B, D>>;
}

type TableNames = "TestA" | "TestB";

interface TestA {
    name: string;
    id: number;
    password: string;
    
}

interface TestB {
    fullName: string;
    id: number;
    alies: string;
    parentId: number;
}

const query = {} as IQuery<TestA, TableNames, NonFunctionPropertyNames<TestA>>


query.InnerJoin<TestB>("TestB", "id", "parentId").Column("")
Here is the issue with JoinNoneFunctionPropertyNames, in the above example Column("") should present the following keys

TestA.name
TestA.id
TestA.password
TestB.id
TestB.alies
TestB.fullName
TestB.parentId

instead I am getting

TestA.name
TestA.id
TestA.password
TestA.alies
TestA.fullName
TestA.parentId
TestB.id
TestB.alies
TestB.fullName
TestB.parentId
TestB.name
TestB.password

how can I change JoinNoneFunctionPropertyNames so that I get the below values instead

TestA.name
TestA.id
TestA.password
TestB.id
TestB.alies
TestB.fullName
TestB.parentId

playground

Upvotes: 0

Views: 40

Answers (0)

Related Questions