Z
Z
zwezew2019-05-24 14:34:44
typescript
zwezew, 2019-05-24 14:34:44

How in the TypeScript interface to set a common type for any elements of an object?

interface Obj {
    elemA: MainType;
    elemB: MainType;
}

In addition to elemA, elemB can also be elemC and so on, and they are all of the same type. How to write an interface so that MainType is applied to all elements without requiring them to be written, as in the example?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Yarkov, 2019-05-24
@zwezew

interface Obj {
    [key: string]: MainType;
    other: OtherType;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question