1

When the type is declared as in the code block below

When declaring a new type C is an object, the key value is the key value of A, and the type of each key is B.

How to declare C with only A and B..?

type A = {
 home: string
 info:string
 about:string
}
type B = "open" | "close"

desired result

type C = {
 home: "open" | "close"
 info:"open" | "close"
 about:"open" | "close"
}
1
  • Why do you even need type A and B? Commented Sep 11, 2021 at 14:24

2 Answers 2

3

You could use in like this:

type C = { [K in keyof A]: B };
Sign up to request clarification or add additional context in comments.

Comments

1

Using the Record type:

type C = Record<keyof A, B>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.