Skip to content

Commit 0ea337f

Browse files
committed
refactor: simplify migrated TS (types, casts, config)
Quality cleanups from a /simplify pass, no behavior or API change: move the public DraggableEvent union into lib/utils/types.ts alongside the other public types (it was the lone public type defined in the entry file) and re-export it from cjs.ts; replace 'as Pick<DraggableState, keyof DraggableState>' with the equivalent 'as DraggableState'; drop DraggableCore's redundant propTypes index-signature annotation to match Draggable; remove inert declaration/emitDeclarationOnly/outDir keys from the root tsconfig (noEmit wins; tsup owns dts emit); fix a stale fixture comment that described build-artifact validation after it was repointed at source.
1 parent 5c8762e commit 0ea337f

6 files changed

Lines changed: 24 additions & 23 deletions

File tree

lib/Draggable.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ class Draggable extends React.Component<Partial<DraggableProps>, DraggableState>
348348
newState.y = y;
349349
}
350350

351-
this.setState(newState as Pick<DraggableState, keyof DraggableState>);
351+
this.setState(newState as DraggableState);
352352
};
353353

354354
render(): ReactElement {

lib/DraggableCore.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export default class DraggableCore extends React.Component<Partial<DraggableCore
7373

7474
static displayName: string | undefined = 'DraggableCore';
7575

76-
static propTypes: {[key: string]: unknown} = {
76+
static propTypes = {
7777
/**
7878
* `allowAnyClick` allows dragging using any mouse button.
7979
* By default, we only accept the left button.

lib/cjs.ts

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,6 @@ export type {
6161
PositionOffsetControlPosition,
6262
} from './DraggableCore';
6363
// `DraggableBounds` was the public name for the internal `Bounds` type.
64-
export type {Bounds as DraggableBounds} from './utils/types';
65-
66-
// `DraggableEvent` is the PUBLIC event type. Historically (typings/index.d.ts) it
67-
// was the broad UNION of the React synthetic and native DOM mouse/touch events a
68-
// consumer might receive — NOT the internal `MouseTouchEvent` (which is the
69-
// `MouseEvent & TouchEvent` intersection the handlers use for convenient field
70-
// access). Aliasing the public type to the intersection would be an API break:
71-
// none of the old union members are assignable to the intersection. Keep the
72-
// union to preserve compatibility.
73-
import type * as React from 'react';
74-
export type DraggableEvent =
75-
| React.MouseEvent<HTMLElement | SVGElement>
76-
| React.TouchEvent<HTMLElement | SVGElement>
77-
| MouseEvent
78-
| TouchEvent;
64+
// `DraggableEvent` is the public event union (defined in ./utils/types alongside
65+
// the other public types — see the note there on why it must stay a union).
66+
export type {Bounds as DraggableBounds, DraggableEvent} from './utils/types';

lib/utils/types.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type * as React from 'react';
2+
13
export type DraggableEventHandler = (e: MouseEvent, data: DraggableData) => void | false;
24

35
export type DraggableData = {
@@ -17,3 +19,16 @@ export type EventHandler<T> = (e: T) => void | false;
1719
// MouseEvent and TouchEvent are provided by the TS DOM lib, including
1820
// changedTouches/targetTouches, so the Flow class shims are no longer needed.
1921
export type MouseTouchEvent = MouseEvent & TouchEvent;
22+
23+
// `DraggableEvent` is the PUBLIC event type a consumer's handlers may receive.
24+
// Historically (the old typings/index.d.ts) it was the broad UNION of React
25+
// synthetic and native DOM mouse/touch events — NOT the internal
26+
// `MouseTouchEvent` intersection above (which exists only for convenient field
27+
// access inside the handlers). Aliasing the public type to the intersection
28+
// would be an API break: none of the union members are assignable to it. Keep
29+
// the union to preserve compatibility.
30+
export type DraggableEvent =
31+
| React.MouseEvent<HTMLElement | SVGElement>
32+
| React.TouchEvent<HTMLElement | SVGElement>
33+
| MouseEvent
34+
| TouchEvent;

test/typeCompat/fixture.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
// Type-level compatibility fixture.
22
//
33
// This file is NOT run; it is compiled by `test/typeCompat.test.ts` via `tsc`
4-
// against the AUTO-GENERATED declaration (build/cjs/cjs.d.ts, aliased to
5-
// "react-draggable"). It asserts that the generated public type surface is
6-
// API-compatible with the OLD hand-written typings/index.d.ts.
4+
// against the source entry (lib/cjs.ts, aliased to "react-draggable") — the same
5+
// public surface the shipped declaration is generated from, checked without
6+
// requiring a prior build. It asserts that surface is API-compatible with the
7+
// OLD hand-written typings/index.d.ts.
78
//
89
// Every exported name and every prop from the old surface is exercised here. If
910
// any export is removed/renamed, or any prop is removed/renamed/retyped

tsconfig.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
"moduleResolution": "bundler",
66
"lib": ["ES2019", "DOM", "DOM.Iterable"],
77
"jsx": "react",
8-
"declaration": true,
9-
"emitDeclarationOnly": false,
10-
"outDir": "build/cjs",
118
"strict": true,
129
"esModuleInterop": true,
1310
"allowSyntheticDefaultImports": true,

0 commit comments

Comments
 (0)