2

I have a object-type with some fields defined. Now I want to dynamically create another object where each fieldname has a $-suffix and contains an observable of the original field-type. I thought I could do this by using keyof and adding the + '$' to it. But this wont transpile.

import { Observable } from 'rxjs';

type AllFields = {
    foo: string,
    bar: number
};

type ObservedFields<T> = {
    [P in keyof T] + '$': Observable<T[P]>;
}

What I want to do:

const myObject: AllFields = {
foo: 'something',
bar: 7
}

const observed: ObservedFields<AllFields> = {
  foo$: Observable<string>,
  bar$: Observable<number>
};
pubkey
  • 617
  • 8
  • 17
  • 2
    Possible duplicate of [Changing Property Name in Typescript Mapped Type](https://stackoverflow.com/questions/44323441/changing-property-name-in-typescript-mapped-type) – jcalz Oct 25 '17 at 01:09

0 Answers0