Typescript - isolating a property from an interface

You can re-use an interface's property by extracting it using normal object access notation eg

interface SomeInterface {
    usefulProperty: string |  object {}

type newType = SomeInterface['usefulProperty']

// now newType is equal to string | object {}

Not only can this save you having to type out stuff twice, but more importantly, should SomeInterface>usefulProperty change, then newType will automatically change.

Share this