#Template Literal Types with name of class as property

4 messages · Page 1 of 1 (latest)

oak onyx
#

I have following type:

type TypeAsProperty<Type> = {
  [Prop in keyof { a: true } as `${Type & string}`]: Type;
};

type Person = {
  id: number;
  firstname: string;
};

type PersonAsProperty = TypeAsProperty<Person>;

I would expect that PersonAsProperty is equal to the following type:

type ResultingType = {Person: Person};

Unfortunately that is not the case. What do I have to do to fix it?

Thanks a lot.

spice umbra
#

@oak onyx I don't think this is possible.

#

Type is not "Person" it's the Person type, i.e. { id: number, firstname: string }

oak onyx