0

Say I have two types in TypeScript:

interface Foo {
  bar: string;
}

interface Baz {
  foo: Foo;
}

Is there a way in TypeScript to flatten Baz (e.g. type FlatBaz = Flat<Baz>), such that the signature looks something like this?

interface FlatBaz {
  "foo.bar": string;
}
Craig Smitham
  • 3,395
  • 4
  • 31
  • 38
  • I'd be interested to know what you're trying to achieve. because your `FlatBaz` type looks like it would be the structure of a type returned from some function – Damian Green May 04 '20 at 19:58
  • 1
    Possible duplicate of [Typescript: deep keyof of a nested object](https://stackoverflow.com/questions/58434389/typescript-deep-keyof-of-a-nested-object) – jcalz May 04 '20 at 20:08
  • @DamianGreen yes - it would be returned from a function. I'm mapping objects to/from query parameters and would like to more strongly type the behavior. – Craig Smitham May 04 '20 at 20:27

2 Answers2

1

No. Currently there is no way to concat string literal types with Typescript:

https://github.com/microsoft/TypeScript/issues/12754

Lodewijk Bogaards
  • 19,777
  • 3
  • 28
  • 52
0

AFAIK, there is no such a thing.

HTN
  • 3,388
  • 1
  • 8
  • 18