I have an object type which has properties of different types
type ExampleType = {
one: string
two: boolean
three: 'A' | 'Union'
}
Is there a shorthand way to explain this same type but with all properties as string?
type ExampleStringType = {
one: string
two: string
three: string
}
In the docs I see some intrinsic string manipulation types but nothing for setting all properties as string. I assume it must be possible. I was imagining something like
const value: AllString<ExampleType> = {
one: "string"
two: "string"
three: "string"
}
You can use keyof to get keys of a specified type, and you can map them to string.
type AllString<T> = {
[key in keyof T]: string;
}
interface ExampleStringType{
[key:string]:string;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With