0

Is there a way to create a new interface that contains only the optional fields of another interface?

declare interface TestInterface {
    mandatory: string,
    optional?: string,
}

declare interface OnlyOptional {
    optional: string
}

type OnlyOptionalExtended = GetOptional<TestInterface>;

I need my OnlyOptional and OnlyOptionalExtended interfaces to be exactly the same.

Adam
  • 4,985
  • 2
  • 29
  • 61
  • The syntax should be `type OnlyOptionalExtended = GetOptional;` – Bergi Nov 13 '20 at 09:06
  • 2
    Ok, but what I need here is the `GetOptional` type. – Adam Nov 13 '20 at 09:08
  • 3
    Does this answer your question? [is there a way to get all required properties of a typescript object](https://stackoverflow.com/questions/52984808/is-there-a-way-to-get-all-required-properties-of-a-typescript-object) – Dane Brouwer Nov 13 '20 at 09:16

0 Answers0