Issue
For example, I have
type Line = {
start: Point;
end: Point;
color: string; //'cyan'/'aquablue'/...
}
But now I want to create new line type on the base of Line, so that it stores color as number:
type HexColorLine = Point & {
color: number;
}
Now I expect the HexColorPoint type be equal to
{
start: Point;
end: Point;
color: number;
}
But it equals to
{
start: Point;
end: Point;
color: string | number;
}
Is there a way to override but not extend the prop type with some short syntax? Do i really have to define entirely new type for this?
Solution
Create a helper type:
type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U;
Usage:
type HexColorLine = Overwrite<Line, { color: number }>
Answered By - Karol Majewski
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.