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

chore: support TypeScript 4.8 #534

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/core/src/engines/Engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Controller } from '../Controller'
import { getEventDetails } from '../utils/events'
import { call } from '../utils/fn'
import { V, computeRubberband } from '../utils/maths'
import { GestureKey, IngKey, State, Vector2 } from '../types'
import { GestureKey, IngKey, StateTypes, Vector2 } from '../types'

/**
* The lib doesn't compute the kinematics on the last event of the gesture
Expand Down Expand Up @@ -179,7 +179,7 @@ export abstract class Engine<Key extends GestureKey> {
* Function ran at the start of the gesture.
* @param event
*/
start(event: NonNullable<State[Key]>['event']) {
start(event: StateTypes[Key]['event']) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ref

const state = this.state
const config = this.config
if (!state._active) {
Expand Down Expand Up @@ -222,7 +222,7 @@ export abstract class Engine<Key extends GestureKey> {
* Computes all sorts of state attributes, including kinematics.
* @param event
*/
compute(event?: NonNullable<State[Key]>['event']) {
compute(event?: StateTypes[Key]['event']) {
const { state, config, shared } = this
state.args = this.args

Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/types/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { State } from './state'
import { State, StateTypes } from './state'
import { Vector2, Target, PointerType } from './utils'

export type GestureKey = Exclude<keyof State, 'shared'>
Expand Down Expand Up @@ -42,7 +42,7 @@ export type GestureOptions<T extends GestureKey> = GenericOptions & {
/**
* The position `offset` will start from.
*/
from?: Vector2 | ((state: NonNullable<State[T]>) => Vector2)
from?: Vector2 | ((state: StateTypes[T]) => Vector2)
/**
* The handler will fire only when the gesture displacement is greater than
* the threshold.
Expand Down Expand Up @@ -152,7 +152,7 @@ export type DragConfig = Omit<CoordinatesConfig<'drag'>, 'axisThreshold' | 'boun
* Limits the gesture `offset` to the specified bounds. Can be a ref or a dom
* node.
*/
bounds?: DragBounds | ((state: State['drag']) => DragBounds)
bounds?: DragBounds | ((state: StateTypes['drag']) => DragBounds)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cared for
image

pointer?: {
/**
* The buttons combination that would trigger the drag. Use `-1` to allow
Expand Down
18 changes: 10 additions & 8 deletions packages/core/src/types/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,14 +252,16 @@ export type EventTypes = {
pinch: PointerEvent | TouchEvent | WheelEvent | WebKitGestureEvent
}

export interface State {
export type StateTypes = {
shared: SharedGestureState
drag?: DragState & { event: EventTypes['drag'] }
wheel?: CoordinatesState & { event: EventTypes['wheel'] }
scroll?: CoordinatesState & { event: EventTypes['scroll'] }
move?: CoordinatesState & { event: EventTypes['move'] }
hover?: CoordinatesState & { event: EventTypes['hover'] }
pinch?: PinchState & { event: EventTypes['pinch'] }
drag: DragState & { event: EventTypes['drag'] }
wheel: CoordinatesState & { event: EventTypes['wheel'] }
scroll: CoordinatesState & { event: EventTypes['scroll'] }
move: CoordinatesState & { event: EventTypes['move'] }
hover: CoordinatesState & { event: EventTypes['hover'] }
pinch: PinchState & { event: EventTypes['pinch'] }
}

export type FullGestureState<Key extends GestureKey> = SharedGestureState & NonNullable<State[Key]>
export type State = Pick<StateTypes, 'shared'> & Partial<Omit<StateTypes, 'shared'>>

export type FullGestureState<Key extends GestureKey> = SharedGestureState & StateTypes[Key]