I have a type:
type first = {
one: number;
two: string;
three: {
four: string,
five: number,
}
}
It is applicable to one instance of a variable that I declare in one part of my application, but not exactly applicable to another (second) instance of a variable.
The type that would be suitable for second instance of a variable would look like this:
type second = {
one: number;
two: string;
three: {
four: string,
five: number[], //difference
}
}
I don't want to declare a new type from scratch for a small difference and would like to assimilate the existing type first
by replacing the type of property three
.
I tried to do it this way:
type second = Pick<first, Exclude<keyof first, 'three'>> & {
three: {
four: string,
five: number[], //difference
}
}
But it gives me an error and I get this type definition on hover:
type second = {
one: number;
two: string;
three: {
four: string,
five: number,
};
three: {
four: string,
five: number,
};
}
Notice 2 properties three
.
What am I doing wrong?