"useSprings" return "object[]" when used in a generic hook #1356
Answered
by
joshuaellis
soukipedia
asked this question in
Support
-
🤓 QuestionI have the following code: type SpringHandler<T> = (index: number) => T & { y: number, immediate: boolean };
function makeSpringsHandler<T>(config: T): SpringHandler<T> {
return (index: number) => ({
...config,
y: 50 * index,
immediate: false,
});
}
type Props<T> = { items: any[], config: T };
function useNonGeneric({ items, config }: Props<{ scale: number, zIndex: number }>) {
const [springs, setSprings] = useSprings(items.length, makeSpringsHandler(config));
return springs;
/**
* Type of springs is:
* {
* scale: SpringValue<number>,
* zIndex: SpringValue<number>,
* y: SpringValue<number>,
* }[]
*/
}
function useGeneric<T>({ items, config }: Props<T>) {
const [springs, setSprings] = useSprings(items.length, makeSpringsHandler(config));
return springs;
/**
* Type of springs is: object[] which is unexpected
* Shouldn't it be { y: SpringValue<number> & { [P in keyof T]: SpringValue<P> } }
*/
} I don't know if it is a bug or just I misunderstand it. |
Beta Was this translation helpful? Give feedback.
Answered by
joshuaellis
Apr 14, 2021
Replies: 1 comment
-
v9 re-writes a lot of the code from v9-rc.3, i'd recommend updating to that and going from there. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
soukipedia
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
v9 re-writes a lot of the code from v9-rc.3, i'd recommend updating to that and going from there.