Here is the problem, I declare a type A which is an object of specific type value.
type A = {
[key: string]: {
value: any;
validate: string;
error: null | string;
required?: boolean;
};
};
I declare a variable without using this type
let b = {
name:{value:"", error:null, validate:"required"},
email:{value:"", error:null, validate:"required"}
}
Then I simply get the all keys type of the object b
type B = (keyof typeof b) // gives type "name" | "email"
Then I get all the keys automatically. Like this
type D = {
[key in B]: {
value: any;
validate: string;
error: null | string;
required?: boolean;
};
};
If I Declare variable b
with the type A
then
let b:A = {
name:{value:"", error:null, validate:"required"},
email:{value:"", error:null, validate:"required"}
}
type B = (keyof typeof b) // gives type string | number
I want to assign variable b
with type A
and get all the keys so that I can use them in the D
type.
Thank you for your time!