#How to combine keys in typescript, and if repetitions appear, then combine types?

1 messages · Page 1 of 1 (latest)

empty crystalBOT
#
teknik2008#0

Preview:```ts
// Need to be converted from R into a generic Result. It will be ideal if the decision is carried out over 4. Now 2

type A = {
i: boolean;
o: void;
};

type B = {
i: string;
o: number;
};

type R = {
A: A;
B: B;
};

// Get type

type Result = {
...```

vapid hedge
#

what if you have a property named '*' though

proud yarrow
#

then combine the types

#

This is needed to type the queue.

empty crystalBOT
#
sandiford#0

Preview:ts ... type T = { [K in keyof A as `*.${K}`]: A[K] | B[K] }

digital vapor
#

@proud yarrow

proud yarrow
#

No, it's just adding stars. I need the full Result type

digital vapor
#

What?

#
type T = {
    "*.i": string | boolean;
    "*.o": number | void;
}
proud yarrow
#

The type I specified is abstract.

I'm trying to make it generic.

I understand what you offered me. But it doesn't suit me. (((

digital vapor
#

So make it generic

#

LOL

vapid hedge
#

i have no clue why i did this

empty crystalBOT
#
that_guy977#0

Preview:ts ... type Transform<T extends object> = { [PP in keyof T extends infer P extends keyof T & string ? P extends P ? keyof T[P] extends infer N extends string ? N extends N ? [P, N] : never : never : never : never as `${PP[0]}.${PP[1]}`]: T[PP[0] & keyof T][PP[1] & keyof T[PP[0] & keyof T]] } & { [K in keyof T & string as `${K}.*`]: T[K][keyof T[K]] } & { [K in T[keyof T] extends infer P ? P extends P ? keyof P & string : never : never as `*.${K}`]: T[keyof T] extends infer P ? P extends P ? P[K & keyof P] : never : never } & { ...

proud yarrow
#

Thank you, this is what we need.

The only thing I need is still in depth 4

Now they key like this

player.transactions.addItems.1

#

it work.

Transform<Transform<Transform<CommandsAll>>>

Thank