0

I hope the topic is not too confusing, but I don't know how to say it better. Let's say I have an object like this in Typescript:

type TypeA = {a : number, b: number, c : {d: number, e: number}}
const ObjA = {a: 1, b: 2, c : {d : 3, e: 4}}

Now I have a second Type which is always a part of TypeA:

type TypeB = {a: number, c: {e: number}}

how would I generate an ObjB from ObjA but instead of all the information in the object it should only have these from TypeB.

Is there a quick and easy way to do that?

Thanks a lot!

Cheers

Nick Vu
  • 14,512
  • 4
  • 21
  • 31
Hannes F
  • 339
  • 2
  • 11
  • Does this answer your question? [Is it possible to restrict TypeScript object to contain only properties defined by its class?](https://stackoverflow.com/questions/49580725/is-it-possible-to-restrict-typescript-object-to-contain-only-properties-defined) – OFRBG Jun 28 '23 at 10:39
  • I do have an idea, but it will make the code really complex and will require a function invocation that will loop through the keys and remove them, but I don't recommend doing something like that so just manually create it – wonderflame Jun 28 '23 at 10:40
  • So you want `function runtimeDeepPick` ? – Dimava Jun 28 '23 at 10:57
  • So are you asking for a solution in *types*, or a solution at *runtime*, or *both*? – kelsny Jun 28 '23 at 16:42
  • both would be interesting! if there is a solution – Hannes F Jul 03 '23 at 08:40

0 Answers0