Skip to content

Commit c7cb407

Browse files
authoredAug 30, 2022
ts: migrate to ts 4.8 (#535)
1 parent 35229b0 commit c7cb407

File tree

22 files changed

+5597
-3532
lines changed

22 files changed

+5597
-3532
lines changed
 

‎.changeset/slimy-zoos-compete.md

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
'@use-gesture/core': patch
3+
---
4+
5+
ts: Typescript 4.8 introduced a new mapping definition for NonNullable which breaks the package types.
6+
7+
```ts
8+
// Native NonNullable Utility Type
9+
10+
// definition on 4.7 and lower
11+
type NonNullable<T> = T extends null | undefined ? never : T
12+
13+
// definition from 4.8
14+
type NonNullable<T> = T & {}
15+
```
16+
17+
This fix reverts the definition of NonNullable so that it works.
18+
More information here: https://github.com/pmndrs/use-gesture/issues/501#issuecomment-1229486104

‎demo/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"@types/react-dom": "^18.0.4",
3131
"@types/three": "^0.140.0",
3232
"@vitejs/plugin-react": "^1.3.2",
33-
"typescript": "^4.6.4",
33+
"typescript": "^4.8.2",
3434
"typescript-plugin-css-modules": "^3.4.0",
3535
"vite": "2.9.9"
3636
}

‎demo/src/sandboxes/cards-stack/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"devDependencies": {
2525
"@types/react": "^18.0.3",
2626
"@types/react-dom": "^18.0.0",
27-
"typescript": "^4.6.4",
27+
"typescript": "^4.8.2",
2828
"typescript-plugin-css-modules": "^3.4.0"
2929
}
3030
}

‎demo/src/sandboxes/dots-connect/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"devDependencies": {
2525
"@types/react": "^18.0.3",
2626
"@types/react-dom": "^18.0.0",
27-
"typescript": "^4.6.4",
27+
"typescript": "^4.8.2",
2828
"typescript-plugin-css-modules": "^3.4.0"
2929
}
3030
}

‎demo/src/sandboxes/draggable-image/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"devDependencies": {
2525
"@types/react": "^18.0.3",
2626
"@types/react-dom": "^18.0.0",
27-
"typescript": "^4.6.4",
27+
"typescript": "^4.8.2",
2828
"typescript-plugin-css-modules": "^3.4.0"
2929
}
3030
}

‎demo/src/sandboxes/draggable-list-prevent-scroll/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"@types/lodash-es": "^4.17.4",
2828
"@types/react": "^18.0.3",
2929
"@types/react-dom": "^18.0.0",
30-
"typescript": "^4.6.4",
30+
"typescript": "^4.8.2",
3131
"typescript-plugin-css-modules": "^3.4.0"
3232
}
3333
}

‎demo/src/sandboxes/draggable-list/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"@types/lodash-es": "^4.17.4",
2929
"@types/react": "^18.0.3",
3030
"@types/react-dom": "^18.0.0",
31-
"typescript": "^4.6.4",
31+
"typescript": "^4.8.2",
3232
"typescript-plugin-css-modules": "^3.4.0"
3333
}
3434
}

‎demo/src/sandboxes/gesture-drag-vanilla/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"@types/lodash-es": "^4.17.4",
2828
"@types/react": "^18.0.3",
2929
"@types/react-dom": "^18.0.0",
30-
"typescript": "^4.6.4",
30+
"typescript": "^4.8.2",
3131
"typescript-plugin-css-modules": "^3.4.0"
3232
}
3333
}

‎demo/src/sandboxes/gesture-move/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"devDependencies": {
2525
"@types/react": "^18.0.3",
2626
"@types/react-dom": "^18.0.0",
27-
"typescript": "^4.6.4",
27+
"typescript": "^4.8.2",
2828
"typescript-plugin-css-modules": "^3.4.0"
2929
}
3030
}

‎demo/src/sandboxes/gesture-simplest/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"@types/lodash-es": "^4.17.4",
2727
"@types/react": "^18.0.3",
2828
"@types/react-dom": "^18.0.0",
29-
"typescript": "^4.6.4",
29+
"typescript": "^4.8.2",
3030
"typescript-plugin-css-modules": "^3.4.0"
3131
}
3232
}

‎demo/src/sandboxes/gesture-three/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"@types/react": "^18.0.3",
2020
"@types/react-dom": "^18.0.0",
2121
"@types/three": "^0.131.0",
22-
"typescript": "^4.6.4",
22+
"typescript": "^4.8.2",
2323
"typescript-plugin-css-modules": "^3.4.0"
2424
},
2525
"scripts": {

‎demo/src/sandboxes/gesture-vanilla/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"@types/lodash-es": "^4.17.4",
2727
"@types/react": "^18.0.3",
2828
"@types/react-dom": "^18.0.0",
29-
"typescript": "^4.6.4",
29+
"typescript": "^4.8.2",
3030
"typescript-plugin-css-modules": "^3.4.0"
3131
}
3232
}

‎demo/src/sandboxes/slide/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"devDependencies": {
2525
"@types/react": "^18.0.3",
2626
"@types/react-dom": "^18.0.0",
27-
"typescript": "^4.6.4",
27+
"typescript": "^4.8.2",
2828
"typescript-plugin-css-modules": "^3.4.0"
2929
}
3030
}

‎demo/src/sandboxes/viewpager/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"@types/lodash-es": "^4.17.4",
3030
"@types/react": "^18.0.3",
3131
"@types/react-dom": "^18.0.0",
32-
"typescript": "^4.6.4",
32+
"typescript": "^4.8.2",
3333
"typescript-plugin-css-modules": "^3.4.0"
3434
}
3535
}

‎demo/tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"esModuleInterop": false,
99
"allowSyntheticDefaultImports": true,
1010
"strict": true,
11+
"strictNullChecks": true,
1112
"forceConsistentCasingInFileNames": true,
1213
"module": "ESNext",
1314
"moduleResolution": "node",

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,6 @@
105105
"react-dom": "^18.1.0",
106106
"size-limit": "^7.0.8",
107107
"tsd": "^0.20.0",
108-
"typescript": "^4.6.4"
108+
"typescript": "^4.8.2"
109109
}
110110
}

‎packages/core/src/engines/Engine.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { getEventDetails } from '../utils/events'
33
import { call } from '../utils/fn'
44
import { V, computeRubberband } from '../utils/maths'
55
import { GestureKey, IngKey, State, Vector2 } from '../types'
6+
import { NonUndefined } from '../types'
67

78
/**
89
* The lib doesn't compute the kinematics on the last event of the gesture
@@ -179,7 +180,7 @@ export abstract class Engine<Key extends GestureKey> {
179180
* Function ran at the start of the gesture.
180181
* @param event
181182
*/
182-
start(event: NonNullable<State[Key]>['event']) {
183+
start(event: NonUndefined<State[Key]>['event']) {
183184
const state = this.state
184185
const config = this.config
185186
if (!state._active) {
@@ -222,7 +223,7 @@ export abstract class Engine<Key extends GestureKey> {
222223
* Computes all sorts of state attributes, including kinematics.
223224
* @param event
224225
*/
225-
compute(event?: NonNullable<State[Key]>['event']) {
226+
compute(event?: NonUndefined<State[Key]>['event']) {
226227
const { state, config, shared } = this
227228
state.args = this.args
228229

‎packages/core/src/types/config.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { State } from './state'
2-
import { Vector2, Target, PointerType } from './utils'
2+
import { Vector2, Target, PointerType, NonUndefined } from './utils'
33

44
export type GestureKey = Exclude<keyof State, 'shared'>
55
export type CoordinatesKey = Exclude<GestureKey, 'pinch'>
@@ -42,7 +42,7 @@ export type GestureOptions<T extends GestureKey> = GenericOptions & {
4242
/**
4343
* The position `offset` will start from.
4444
*/
45-
from?: Vector2 | ((state: NonNullable<State[T]>) => Vector2)
45+
from?: Vector2 | ((state: NonUndefined<State[T]>) => Vector2)
4646
/**
4747
* The handler will fire only when the gesture displacement is greater than
4848
* the threshold.

‎packages/core/src/types/state.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { GestureKey } from './config'
2-
import { Vector2, WebKitGestureEvent } from './utils'
2+
import { NonUndefined, Vector2, WebKitGestureEvent } from './utils'
33

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

@@ -262,4 +262,4 @@ export interface State {
262262
pinch?: PinchState & { event: EventTypes['pinch'] }
263263
}
264264

265-
export type FullGestureState<Key extends GestureKey> = SharedGestureState & NonNullable<State[Key]>
265+
export type FullGestureState<Key extends GestureKey> = SharedGestureState & NonUndefined<State[Key]>

‎packages/core/src/types/utils.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ export type WebKitGestureEvent = PointerEvent & { scale: number; rotation: numbe
33
export type Target = EventTarget | { current: EventTarget | null }
44
export type PointerType = 'mouse' | 'touch' | 'pen'
55

6-
// rip off from React types
7-
6+
// replaces NonUndefined from 4.7 and inferior versions
7+
export type NonUndefined<T> = T extends undefined ? never : T
88
export type EventHandler<E extends Event = Event> = (event: E) => void
99

10+
// rip off from React types
1011
export interface DOMHandlers {
1112
// Clipboard Events
1213
onCopy?: EventHandler<ClipboardEvent>

‎pnpm-lock.yaml

+5,552-3,508
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎tsconfig.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
2525
/* Strict Type-Checking Options */
2626
"strict": true /* Enable all strict type-checking options. */,
27-
"noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
28-
// "strictNullChecks": true, /* Enable strict null checks. */
27+
"noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
28+
"strictNullChecks": true, /* Enable strict null checks. */
2929
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
3030
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
3131
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */

0 commit comments

Comments
 (0)
Please sign in to comment.