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(types): use official NonNullable again #548

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
5 changes: 2 additions & 3 deletions packages/core/src/engines/Engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { getEventDetails } from '../utils/events'
import { call } from '../utils/fn'
import { V, computeRubberband } from '../utils/maths'
import { GestureKey, IngKey, State, Vector2 } from '../types'
import { NonUndefined } from '../types'

/**
* The lib doesn't compute the kinematics on the last event of the gesture
Expand Down Expand Up @@ -180,7 +179,7 @@ export abstract class Engine<Key extends GestureKey> {
* Function ran at the start of the gesture.
* @param event
*/
start(event: NonUndefined<State[Key]>['event']) {
start(event: NonNullable<State[Key]>['event']) {
const state = this.state
const config = this.config
if (!state._active) {
Expand Down Expand Up @@ -223,7 +222,7 @@ export abstract class Engine<Key extends GestureKey> {
* Computes all sorts of state attributes, including kinematics.
* @param event
*/
compute(event?: NonUndefined<State[Key]>['event']) {
compute(event?: NonNullable<State[Key]>['event']) {
const { state, config, shared } = this
state.args = this.args

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

export type GestureKey = Exclude<keyof State, 'shared'>
export type CoordinatesKey = Exclude<GestureKey, 'pinch'>
Expand Down Expand Up @@ -42,7 +42,7 @@ export type GestureOptions<T extends GestureKey> = GenericOptions & {
/**
* The position `offset` will start from.
*/
from?: Vector2 | ((state: NonUndefined<State[T]>) => Vector2)
from?: Vector2 | ((state: NonNullable<State[T]>) => Vector2)
/**
* The handler will fire only when the gesture displacement is greater than
* the threshold.
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/types/state.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { GestureKey } from './config'
import { NonUndefined, Vector2, WebKitGestureEvent } from './utils'
import { Vector2, WebKitGestureEvent } from './utils'

export type IngKey = 'dragging' | 'wheeling' | 'moving' | 'hovering' | 'scrolling' | 'pinching'

Expand Down Expand Up @@ -262,4 +262,4 @@ export interface State {
pinch?: PinchState & { event: EventTypes['pinch'] }
}

export type FullGestureState<Key extends GestureKey> = SharedGestureState & NonUndefined<State[Key]>
export type FullGestureState<Key extends GestureKey> = SharedGestureState & NonNullable<State[Key]>
2 changes: 0 additions & 2 deletions packages/core/src/types/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ export type WebKitGestureEvent = PointerEvent & { scale: number; rotation: numbe
export type Target = EventTarget | { current: EventTarget | null }
export type PointerType = 'mouse' | 'touch' | 'pen'

// replaces NonUndefined from 4.7 and inferior versions
export type NonUndefined<T> = T extends undefined ? never : T
export type EventHandler<E extends Event = Event> = (event: E) => void

// rip off from React types
Expand Down