Skip to content
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

fix types #29

Merged
merged 13 commits into from
Jan 21, 2023
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

## Unreleased
* Fixed roblox-ts typings ([Xuleos](https://github.com/Xuleos) in [#29](https://github.com/chriscerie/roact-spring/pull/29))
* Fixed roblox-ts false positives when running plugins on roblox-ts games ([sasial-dev](https://github.com/sasial-dev) in [#40](https://github.com/chriscerie/roact-spring/pull/40))

## 1.1.2 (Nov 29, 2022)
Expand Down
42 changes: 20 additions & 22 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 3 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-roblox-ts": "^0.0.32",
"prettier": "^2.5.1",
"typescript": "^4.5.5"
},
"peerDependencies": {
"@rbxts/roact": "^1.4.0-ts.2",
"@rbxts/roact-hooks": "^0.3.0-ts.2"
"typescript": "^4.5.5",
"@rbxts/roact": "*",
"@rbxts/roact-hooks": "*"
}
}
16 changes: 8 additions & 8 deletions src/Controller.d.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { Binding } from '@rbxts/roact';
import { AnimatableType, AnimationProps } from './types/common';
import { AnimationProps, AnimationStyle, SharedAnimationProps } from './types/common';

export type ControllerProps = AnimationProps & {
[key: string]: AnimatableType;
};
export type ControllerProps<T extends AnimationStyle> = (AnimationProps<T> | T) & SharedAnimationProps;

export interface ControllerApi {
start(startProps?: ControllerProps): Promise<void>;
stop(keys?: [string]): Promise<void>;
pause(keys?: [string]): Promise<void>;
start(this: void, startProps?: ControllerProps<AnimationStyle>): Promise<void>;
stop(this: void, keys?: [string]): Promise<void>;
pause(this: void, keys?: [string]): Promise<void>;
}

declare interface Constructor {
new (props: ControllerProps): LuaTuple<[{ [key: string]: Binding<AnimatableType> }, ControllerApi]>;
new <T extends AnimationStyle>(props: ControllerProps<T>): LuaTuple<
[{ [key in keyof T]: Binding<T[key]> }, ControllerApi]
>;
}

declare const Controller: Constructor;
Expand Down
11 changes: 2 additions & 9 deletions src/constants.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export type EasingFunction = (t: number) => number;

declare interface Config {
export interface Config {
default: { tension: 170; friction: 26 };
gentle: { tension: 120; friction: 14 };
wobbly: { tension: 180; friction: 12 };
Expand All @@ -9,7 +9,7 @@ declare interface Config {
molasses: { tension: 280; friction: 120 };
}

declare interface EasingDictionary {
export interface EasingDictionary {
linear: EasingFunction;
easeInQuad: EasingFunction;
easeOutQuad: EasingFunction;
Expand Down Expand Up @@ -42,10 +42,3 @@ declare interface EasingDictionary {
easeOutBounce: EasingFunction;
easeInOutBounce: EasingFunction;
}

declare interface Constants {
configs: Config;
easings: EasingDictionary;
}
declare const constants: Constants;
export default constants;
18 changes: 11 additions & 7 deletions src/hooks/useSpring.d.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { CoreHooks } from '@rbxts/roact-hooks';
import { Binding } from '@rbxts/roact';
import { AnimatableType } from '../types/common';
import { ControllerProps, ControllerApi } from '../Controller';
import { CoreHooks } from '@rbxts/roact-hooks';
import { ControllerApi, ControllerProps } from '../Controller';
import { AnimationStyle } from '../types/common';

declare interface UseSpring {
(hooks: CoreHooks, props: ControllerProps, dependencies?: Array<unknown>): { [key: string]: Binding<AnimatableType> };
(hooks: CoreHooks, props: () => ControllerProps, dependencies?: Array<unknown>): LuaTuple<
[{ [key: string]: Binding<AnimatableType> }, ControllerApi]
>;
<T extends AnimationStyle>(hooks: CoreHooks, props: ControllerProps<T>, dependencies?: Array<unknown>): {
[key in keyof T]: Binding<T[key]>;
};
<T extends ControllerProps<AnimationStyle>>(
hooks: CoreHooks,
props: () => T,
dependencies?: Array<unknown>
): LuaTuple<[{ [key in keyof T]: Binding<T[key]> }, ControllerApi]>;
}

declare const useSpring: UseSpring;
Expand Down
30 changes: 20 additions & 10 deletions src/hooks/useSprings.d.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
import { CoreHooks } from '@rbxts/roact-hooks';
import { Binding } from '@rbxts/roact';
import { AnimatableType } from '../../src/types/common';
import { ControllerProps, ControllerApi } from '../Controller';
import { CoreHooks } from '@rbxts/roact-hooks';
import { AnimationStyle } from '../../src/types/common';
import { ControllerProps } from '../Controller';

export type UseSpringsApi = {
[K in keyof ControllerApi]: (fn: (i: number) => Parameters<ControllerApi[K]>[0]) => ReturnType<ControllerApi[K]>;
export type UseSpringsApi<T extends AnimationStyle> = {
start(this: void, fn?: (i: number) => ControllerProps<T>): Promise<void>;
stop(this: void, keys?: [string]): Promise<void>;
pause(this: void, keys?: [string]): Promise<void>;
};

declare interface UseSprings {
(hooks: CoreHooks, length: number, props: ControllerProps, dependencies?: Array<unknown>): Array<{
[key: string]: Binding<AnimatableType>;
<T extends AnimationStyle>(
hooks: CoreHooks,
length: number,
props: Array<ControllerProps<T>>,
dependencies?: Array<unknown>
): Array<{
[key in keyof T]: Binding<T[key]>;
}>;
(hooks: CoreHooks, length: number, props: (i: number) => ControllerProps, dependencies?: Array<unknown>): LuaTuple<
[Array<{ [key: string]: Binding<AnimatableType> }>, UseSpringsApi]
>;
<T extends AnimationStyle>(
hooks: CoreHooks,
length: number,
props: (i: number) => ControllerProps<T>,
dependencies?: Array<unknown>
): LuaTuple<[Array<{ [key in keyof T]: Binding<T[key]> }>, UseSpringsApi<T>]>;
}

declare const useSprings: UseSprings;
Expand Down
24 changes: 16 additions & 8 deletions src/hooks/useTrail.d.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
import { CoreHooks } from '@rbxts/roact-hooks';
import { Binding } from '@rbxts/roact';
import { AnimatableType } from '../../src/types/common';
import { ControllerProps, ControllerApi } from '../Controller';
import { CoreHooks } from '@rbxts/roact-hooks';
import { AnimatableType, AnimationStyle } from '../../src/types/common';
import { ControllerProps } from '../Controller';
import { UseSpringsApi } from './useSprings';

declare interface UseTrail {
(hooks: CoreHooks, length: number, props: ControllerProps, dependencies?: Array<unknown>): Array<{
[key: string]: Binding<AnimatableType>;
<T extends AnimationStyle>(
hooks: CoreHooks,
length: number,
props: Array<ControllerProps<T>>,
dependencies?: Array<unknown>
): Array<{
[key in keyof T]: Binding<T[key]>;
}>;
(hooks: CoreHooks, length: number, props: (i: number) => ControllerProps, dependencies?: Array<unknown>): LuaTuple<
[Array<{ [key: string]: Binding<AnimatableType> }>, UseSpringsApi]
>;
<T extends AnimationStyle>(
hooks: CoreHooks,
length: number,
props: (i: number) => ControllerProps<T>,
dependencies?: Array<unknown>
): LuaTuple<[Array<{ [key in keyof T]: Binding<T[key]> }>, UseSpringsApi<T>]>;
}

declare const useTrail: UseTrail;
Expand Down
9 changes: 6 additions & 3 deletions src/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { Config, EasingDictionary } from './constants';
import Controller from './Controller';
import useSpring from './hooks/useSpring';
import useSprings from './hooks/useSprings';
import useTrail from './hooks/useTrail';
import Controller from './Controller';
import constants from './constants';

export { useSpring, useSprings, useTrail, Controller, constants };
export { useSpring, useSprings, useTrail, Controller };

export const configs: Config;
export const easings: EasingDictionary;
19 changes: 15 additions & 4 deletions src/types/common.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,22 @@ import { EasingFunction } from '../constants';

export type AnimatableType = number | UDim | UDim2 | Vector2 | Vector3 | Color3;

export type AnimationProps = {
from?: AnimatableType;
to?: AnimatableType;
delay?: number;
type AnimationStyle = {
[key: string]: AnimatableType;
};

export type AnimationProps<T extends AnimationStyle> = {
from?: T;
to?: T;
};

export type SharedAnimationProps = {
loop?: boolean;
reset?: boolean;
default?: boolean;
config?: AnimationConfigs;
immediate?: boolean;
delay?: number;
};

export interface AnimationConfigs {
Expand Down