jaxtrax

jaxtrax

TypeScript - re-use an interface's property using object access notation

Re-use an interface's property by extracting it using normal object access notation

This keeps the type in line/sync with the interface, eg if the interface property changes then the type will be updated automatically

interface MyInterface {
    someComplicatedProperty: string | number | object ... 
}

type complicatedType = MyInterface['someComplicatedProperty']

// now complicatedType is equal to string | number | object ...
 
Share this