JillAndMe
JillAndMe

Reputation: 4551

typescript: how to pick a type in object?

I'm trying to get a type in object which belong to interface

interface Action {
 type: string,
 payload: {
    name: string
 }
}

In this case I want to pick payload.name type how to do this?

What I tried is Pick<Action , "payload.name">, but failed any ideas?

Upvotes: 0

Views: 141

Answers (1)

钵钵鸡实力代购
钵钵鸡实力代购

Reputation: 1042

type A = Action["payload"]["name"]  // yield string

direct access to the index will give you the desired type

Upvotes: 3

Related Questions