Skip to content

Commit

Permalink
ts: migrate to ts 4.8 (#535)
Browse files Browse the repository at this point in the history
  • Loading branch information
dbismut authored Aug 30, 2022
1 parent 35229b0 commit c7cb407
Show file tree
Hide file tree
Showing 22 changed files with 5,597 additions and 3,532 deletions.
18 changes: 18 additions & 0 deletions .changeset/slimy-zoos-compete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
'@use-gesture/core': patch
---

ts: Typescript 4.8 introduced a new mapping definition for NonNullable which breaks the package types.

```ts
// Native NonNullable Utility Type

// definition on 4.7 and lower
type NonNullable<T> = T extends null | undefined ? never : T

// definition from 4.8
type NonNullable<T> = T & {}
```
This fix reverts the definition of NonNullable so that it works.
More information here: https://github.com/pmndrs/use-gesture/issues/501#issuecomment-1229486104
2 changes: 1 addition & 1 deletion demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"@types/react-dom": "^18.0.4",
"@types/three": "^0.140.0",
"@vitejs/plugin-react": "^1.3.2",
"typescript": "^4.6.4",
"typescript": "^4.8.2",
"typescript-plugin-css-modules": "^3.4.0",
"vite": "2.9.9"
}
Expand Down
2 changes: 1 addition & 1 deletion demo/src/sandboxes/cards-stack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"devDependencies": {
"@types/react": "^18.0.3",
"@types/react-dom": "^18.0.0",
"typescript": "^4.6.4",
"typescript": "^4.8.2",
"typescript-plugin-css-modules": "^3.4.0"
}
}
2 changes: 1 addition & 1 deletion demo/src/sandboxes/dots-connect/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"devDependencies": {
"@types/react": "^18.0.3",
"@types/react-dom": "^18.0.0",
"typescript": "^4.6.4",
"typescript": "^4.8.2",
"typescript-plugin-css-modules": "^3.4.0"
}
}
2 changes: 1 addition & 1 deletion demo/src/sandboxes/draggable-image/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"devDependencies": {
"@types/react": "^18.0.3",
"@types/react-dom": "^18.0.0",
"typescript": "^4.6.4",
"typescript": "^4.8.2",
"typescript-plugin-css-modules": "^3.4.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"@types/lodash-es": "^4.17.4",
"@types/react": "^18.0.3",
"@types/react-dom": "^18.0.0",
"typescript": "^4.6.4",
"typescript": "^4.8.2",
"typescript-plugin-css-modules": "^3.4.0"
}
}
2 changes: 1 addition & 1 deletion demo/src/sandboxes/draggable-list/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"@types/lodash-es": "^4.17.4",
"@types/react": "^18.0.3",
"@types/react-dom": "^18.0.0",
"typescript": "^4.6.4",
"typescript": "^4.8.2",
"typescript-plugin-css-modules": "^3.4.0"
}
}
2 changes: 1 addition & 1 deletion demo/src/sandboxes/gesture-drag-vanilla/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"@types/lodash-es": "^4.17.4",
"@types/react": "^18.0.3",
"@types/react-dom": "^18.0.0",
"typescript": "^4.6.4",
"typescript": "^4.8.2",
"typescript-plugin-css-modules": "^3.4.0"
}
}
2 changes: 1 addition & 1 deletion demo/src/sandboxes/gesture-move/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"devDependencies": {
"@types/react": "^18.0.3",
"@types/react-dom": "^18.0.0",
"typescript": "^4.6.4",
"typescript": "^4.8.2",
"typescript-plugin-css-modules": "^3.4.0"
}
}
2 changes: 1 addition & 1 deletion demo/src/sandboxes/gesture-simplest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"@types/lodash-es": "^4.17.4",
"@types/react": "^18.0.3",
"@types/react-dom": "^18.0.0",
"typescript": "^4.6.4",
"typescript": "^4.8.2",
"typescript-plugin-css-modules": "^3.4.0"
}
}
2 changes: 1 addition & 1 deletion demo/src/sandboxes/gesture-three/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"@types/react": "^18.0.3",
"@types/react-dom": "^18.0.0",
"@types/three": "^0.131.0",
"typescript": "^4.6.4",
"typescript": "^4.8.2",
"typescript-plugin-css-modules": "^3.4.0"
},
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion demo/src/sandboxes/gesture-vanilla/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"@types/lodash-es": "^4.17.4",
"@types/react": "^18.0.3",
"@types/react-dom": "^18.0.0",
"typescript": "^4.6.4",
"typescript": "^4.8.2",
"typescript-plugin-css-modules": "^3.4.0"
}
}
2 changes: 1 addition & 1 deletion demo/src/sandboxes/slide/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"devDependencies": {
"@types/react": "^18.0.3",
"@types/react-dom": "^18.0.0",
"typescript": "^4.6.4",
"typescript": "^4.8.2",
"typescript-plugin-css-modules": "^3.4.0"
}
}
2 changes: 1 addition & 1 deletion demo/src/sandboxes/viewpager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"@types/lodash-es": "^4.17.4",
"@types/react": "^18.0.3",
"@types/react-dom": "^18.0.0",
"typescript": "^4.6.4",
"typescript": "^4.8.2",
"typescript-plugin-css-modules": "^3.4.0"
}
}
1 change: 1 addition & 0 deletions demo/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"esModuleInterop": false,
"allowSyntheticDefaultImports": true,
"strict": true,
"strictNullChecks": true,
"forceConsistentCasingInFileNames": true,
"module": "ESNext",
"moduleResolution": "node",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,6 @@
"react-dom": "^18.1.0",
"size-limit": "^7.0.8",
"tsd": "^0.20.0",
"typescript": "^4.6.4"
"typescript": "^4.8.2"
}
}
5 changes: 3 additions & 2 deletions packages/core/src/engines/Engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ 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 @@ -179,7 +180,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: NonUndefined<State[Key]>['event']) {
const state = this.state
const config = this.config
if (!state._active) {
Expand Down Expand Up @@ -222,7 +223,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?: 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/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { State } from './state'
import { Vector2, Target, PointerType } from './utils'
import { Vector2, Target, PointerType, NonUndefined } 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: NonNullable<State[T]>) => Vector2)
from?: Vector2 | ((state: NonUndefined<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 { 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]>
5 changes: 3 additions & 2 deletions packages/core/src/types/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ export type WebKitGestureEvent = PointerEvent & { scale: number; rotation: numbe
export type Target = EventTarget | { current: EventTarget | null }
export type PointerType = 'mouse' | 'touch' | 'pen'

// rip off from React types

// 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
export interface DOMHandlers {
// Clipboard Events
onCopy?: EventHandler<ClipboardEvent>
Expand Down
Loading

0 comments on commit c7cb407

Please sign in to comment.