-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
fix: getColorPalette indexing #93699
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
type NextTuple<T extends unknown[], A extends unknown[] = []> = T extends [ | ||
infer _First, | ||
...infer Rest, | ||
] | ||
? // eslint-disable-next-line @typescript-eslint/no-restricted-types | ||
Record<A['length'], Rest extends [] ? never : Rest[0]> & | ||
NextTuple<Rest, [...A, unknown]> | ||
: Record<number, unknown>; | ||
|
||
type NextMap = NextTuple<TupleOf<ColorLength>>; | ||
type Next<R extends ValidLengthArgument> = NextMap[R]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
coincidentally, we can now simplify the types greatly because we don’t need to look at the “next” element, as this +1 logic is gone.
|
||
const colors = theme.chart.getColorPalette(2); | ||
|
||
expectTypeOf(colors).toEqualTypeOf<readonly ['#444674', '#d6567f', '#f2b712']>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’ve added a type test with the expect-type
library. This is what vitest
is using under the hood too and it’ll allow us to write more type-level tests in the future.
The `getColorPalette` function was returning one too many elements: If we invoke `getColorPalette(2)`, it returned an array with 4 elements. The desired behaviour is for it to return 3 elements when invoked with `getColorPalette(2)`, because we’d want the indices 0,1,2 to be available on it.
The
getColorPalette
function was returning one too many elements: If we invokegetColorPalette(2)
, it returned an array with 4 elements.The desired behaviour is for it to return 3 elements when invoked with
getColorPalette(2)
, because we’d want the indices 0,1,2 to be available on it.