-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
More TypeScript updates #398
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
export type UseSpringProps<DS extends UseSpringBaseProps> = Merge< | ||
DS, | ||
export type UseSpringProps<DS extends object> = Merge< | ||
DS & UseSpringBaseProps, |
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.
This change fixes autocomplete so it shows UseSpringBaseProps
' properties on autocomplete
@@ -65,6 +86,12 @@ export type UseSpringProps<DS extends UseSpringBaseProps> = Merge< | |||
> | |||
|
|||
// there's a third value in the tuple but it's not public API (?) | |||
export function useSpring<DS extends CSSProperties>( | |||
values: UseSpringProps<DS & CSSProperties> |
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.
This trick lets CSSProperties show up on autocomplete by default (as long as no property that you add is incompatible with CSSProperties itself; then it falls back to the other overloads)
@@ -64,7 +64,7 @@ export interface SpringBaseProps { | |||
onStart?(): void | |||
} | |||
|
|||
export interface SpringProps<DS extends object = {}> { | |||
export interface SpringProps<DS extends object = {}> extends SpringBaseProps { |
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.
Added this to address #386
* Prevents animation if true, you can also pass individual keys | ||
* @default false | ||
*/ | ||
immediate?: boolean | string[] | ((key: string) => boolean) |
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.
Did immediate
ever actually accept string[]
? I can't find it in the code (in fact if it's an array it's just treated as always true
in the Controller
). This made it incompatible with SpringBaseProps
so I had to remove the string[]
.
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.
@Kovensky No, immediate can be a boolean or a function returning boolean. This could be a left over.
As I try to actually make use of this in a real project I noticed the type definition for I also wonder if it's possible to attach |
transitions return Array<{ item, key, props, state }>, wheresare state can be enter|leave|update and props is an object that contains animated values (which can interpolate). |
Yeah, the output type is (almost) correct, but also very wrong because the input type is wrong. First, it assumes that, like |
This we'll change soon, see: #393 i guess it should be useTransition(input, keys, config), just like useTrail(items, config). Can we anticipate this change already and exclude items, or will TS make it impossible to use? |
I think it has to be done at the same time, because (Somewhat related: |
@Kovensky I apologize if you've already considered this approach, but I had fairly primitive types I was using for just import { SpringConfig } from 'react-spring';
declare module 'react-spring' {
type SpringOptions<T> = {
config?: SpringConfig | ((key: string) => SpringConfig);
} & T;
type SpringSetter<T> = (options: Partial<SpringOptions<T>>) => void;
type InterpolationOptions<T, U = T> = {
range: T[];
output: U[];
};
interface InterpolationFn<T> {
<U>(options: InterpolationOptions<T, U>): Interpolation<U> & U & string;
(interpolator: (params: T) => string): Interpolation<T> & T & string;
}
type Interpolation<T> = {
interpolate: InterpolationFn<T>;
getValue: () => T;
} & T;
type AnimatedValue<T> = { [K in keyof T]: Interpolation<T[K]> };
export function useSpring<T>(
options: SpringOptions<T>,
): [AnimatedValue<T>, SpringSetter<T>];
} The new hooks may be more complex in a way that's prohibitive of using this. |
I've actually opened up a PR that adds the typings for chains. |
More TypeScript updates
Addresses what I could from #383, and adds types for
useChain
.