Imagine we have the following input type:
interface Input {
name: string;
heightCm: number;
dob: Date;
}
I would like to write a function that can produce the following output type based on this input:
interface Output {
name: boolean;
heightCm: boolean;
dob: boolean;
}
In other words, a function that copies the structure of input and returns that structure as output, setting all values as booleans.
The function signature would look something like this:
interface GenericMap<T> {
[key: string]: T;
}
type InputToOutput<In, Out extends GenericMap<boolean>> = (input: In) => Out;
If the type of the Input property was originally a string, mark that property as true, otherwise mark as false.
E.g. the function would produce the following result based on Input above:
{
name: true,
heightCm: false,
dob: false
}
But most importantly, it needs to be type-safe, such that I can receive intellisense on the resulting object.
Help greatly appreciated!