Skip to content

Commit

Permalink
ts: trying stuff to fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
dbismut committed Aug 28, 2022
1 parent c92d259 commit 0f97c17
Show file tree
Hide file tree
Showing 7 changed files with 2,804 additions and 4,940 deletions.
4 changes: 2 additions & 2 deletions demo/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"esModuleInterop": false,
"allowSyntheticDefaultImports": true,
"strict": true,
"strictNullChecks": true,
"forceConsistentCasingInFileNames": true,
"module": "ESNext",
"moduleResolution": "Node",
Expand All @@ -18,6 +19,5 @@
"sourceMap": true,
"plugins": [{ "name": "typescript-plugin-css-modules" }]
},
"include": ["./src"],
"references": [{ "path": "./tsconfig.node.json" }]
"include": ["./src"]
}
9 changes: 0 additions & 9 deletions demo/tsconfig.node.json

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
"react-dom": "^18.2.0",
"size-limit": "^8.0.1",
"tsd": "^0.23.0",
"typescript": "^4.7.4",
"typescript": "^4.8.2",
"vue": "^3.2.37"
}
}
11 changes: 5 additions & 6 deletions packages/core/src/engines/Engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { getEventDetails } from '../utils/events'
import { call } from '../utils/fn'
import { V, computeRubberband } from '../utils/maths'
import { GestureKey, IngKey, Vector2 } from '../types'
import { NonUndefined } from '../types'
import { State } from '../types'

/**
* The lib doesn't compute the kinematics on the last event of the gesture
Expand Down Expand Up @@ -37,7 +39,7 @@ export interface Engine<Key extends GestureKey> {
* `state._active` or `state._blocked` flags if the gesture isn't intentional.
* @param event
*/
axisIntent?(event?: UIEvent): void
axisIntent?(event?: NonUndefined<State[Key]>['event']): void

restrictToAxis?(movement: Vector2): void
}
Expand Down Expand Up @@ -179,10 +181,7 @@ export abstract class Engine<Key extends GestureKey> {
* Function ran at the start of the gesture.
* @param event
*/
start(event: UIEvent) {
// TODO 28.08.22
// this should be the actual type of Event NonNullable<State[Key]>['event']
// but it now throws an error I'm not sure why
start(event: NonUndefined<State[Key]>['event']) {
const state = this.state
const config = this.config
if (!state._active) {
Expand Down Expand Up @@ -225,7 +224,7 @@ export abstract class Engine<Key extends GestureKey> {
* Computes all sorts of state attributes, including kinematics.
* @param event
*/
compute(event?: UIEvent) {
compute(event?: NonUndefined<State[Key]>['event']) {
const { state, config, shared } = this
state.args = this.args

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 { Vector2, WebKitGestureEvent } from './utils'
import { NonUndefined, 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 & NonNullable<State[Key]>
export type FullGestureState<Key extends GestureKey> = SharedGestureState & NonUndefined<State[Key]>
2 changes: 1 addition & 1 deletion packages/core/src/types/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export type Vector2 = [number, number]
export type WebKitGestureEvent = PointerEvent & { scale: number; rotation: number }
export type Target = EventTarget | { current: EventTarget | null }
export type PointerType = 'mouse' | 'touch' | 'pen'

export type NonUndefined<T> = T extends undefined ? never : T
// rip off from React types

export type EventHandler<E extends Event = Event> = (event: E) => void
Expand Down
Loading

0 comments on commit 0f97c17

Please sign in to comment.