Skip to content

Commit 08e265e

Browse files
committed
fix(types): remove global module declaration to prevent type pollution
Removes the `declare module 'react-draggable'` wrapper from TypeScript definitions and uses direct exports instead. This fixes type pollution issues when multiple versions of react-draggable end up in a project's dependencies. The global module declaration is unnecessary as TypeScript will automatically associate the typings with the `react-draggable` module since they're declared in package.json. Closes #690
1 parent 1d1ba06 commit 08e265e

File tree

2 files changed

+62
-59
lines changed

2 files changed

+62
-59
lines changed

typings/index.d.ts

Lines changed: 55 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,66 @@
1-
declare module 'react-draggable' {
2-
import * as React from 'react';
1+
import * as React from 'react';
32

4-
export interface DraggableBounds {
5-
left?: number
6-
right?: number
7-
top?: number
8-
bottom?: number
9-
}
3+
export interface DraggableBounds {
4+
left?: number
5+
right?: number
6+
top?: number
7+
bottom?: number
8+
}
109

11-
export interface DraggableProps extends DraggableCoreProps {
12-
axis: 'both' | 'x' | 'y' | 'none',
13-
bounds: DraggableBounds | string | false ,
14-
defaultClassName: string,
15-
defaultClassNameDragging: string,
16-
defaultClassNameDragged: string,
17-
defaultPosition: ControlPosition,
18-
positionOffset: PositionOffsetControlPosition,
19-
position: ControlPosition
20-
}
10+
export interface DraggableProps extends DraggableCoreProps {
11+
axis: 'both' | 'x' | 'y' | 'none',
12+
bounds: DraggableBounds | string | false ,
13+
defaultClassName: string,
14+
defaultClassNameDragging: string,
15+
defaultClassNameDragged: string,
16+
defaultPosition: ControlPosition,
17+
positionOffset: PositionOffsetControlPosition,
18+
position: ControlPosition
19+
}
2120

22-
export type DraggableEvent = React.MouseEvent<HTMLElement | SVGElement>
23-
| React.TouchEvent<HTMLElement | SVGElement>
24-
| MouseEvent
25-
| TouchEvent
21+
export type DraggableEvent = React.MouseEvent<HTMLElement | SVGElement>
22+
| React.TouchEvent<HTMLElement | SVGElement>
23+
| MouseEvent
24+
| TouchEvent
2625

27-
export type DraggableEventHandler = (
28-
e: DraggableEvent,
29-
data: DraggableData
30-
) => void | false;
26+
export type DraggableEventHandler = (
27+
e: DraggableEvent,
28+
data: DraggableData
29+
) => void | false;
3130

32-
export interface DraggableData {
33-
node: HTMLElement,
34-
x: number, y: number,
35-
deltaX: number, deltaY: number,
36-
lastX: number, lastY: number
37-
}
31+
export interface DraggableData {
32+
node: HTMLElement,
33+
x: number, y: number,
34+
deltaX: number, deltaY: number,
35+
lastX: number, lastY: number
36+
}
3837

39-
export type ControlPosition = {x: number, y: number};
38+
export type ControlPosition = {x: number, y: number};
4039

41-
export type PositionOffsetControlPosition = {x: number|string, y: number|string};
40+
export type PositionOffsetControlPosition = {x: number|string, y: number|string};
4241

43-
export interface DraggableCoreProps {
44-
allowAnyClick: boolean,
45-
allowMobileScroll: boolean,
46-
cancel: string,
47-
children?: React.ReactNode,
48-
disabled: boolean,
49-
enableUserSelectHack: boolean,
50-
offsetParent: HTMLElement,
51-
grid: [number, number],
52-
handle: string,
53-
nodeRef?: React.RefObject<HTMLElement | null>,
54-
onStart: DraggableEventHandler,
55-
onDrag: DraggableEventHandler,
56-
onStop: DraggableEventHandler,
57-
onMouseDown: (e: MouseEvent) => void,
58-
scale: number
59-
}
42+
export interface DraggableCoreProps {
43+
allowAnyClick: boolean,
44+
allowMobileScroll: boolean,
45+
cancel: string,
46+
children?: React.ReactNode,
47+
disabled: boolean,
48+
enableUserSelectHack: boolean,
49+
offsetParent: HTMLElement,
50+
grid: [number, number],
51+
handle: string,
52+
nodeRef?: React.RefObject<HTMLElement | null>,
53+
onStart: DraggableEventHandler,
54+
onDrag: DraggableEventHandler,
55+
onStop: DraggableEventHandler,
56+
onMouseDown: (e: MouseEvent) => void,
57+
scale: number
58+
}
6059

61-
export default class Draggable extends React.Component<Partial<DraggableProps>, {}> {
62-
static defaultProps : DraggableProps;
63-
}
60+
export default class Draggable extends React.Component<Partial<DraggableProps>, {}> {
61+
static defaultProps : DraggableProps;
62+
}
6463

65-
export class DraggableCore extends React.Component<Partial<DraggableCoreProps>, {}> {
66-
static defaultProps : DraggableCoreProps;
67-
}
64+
export class DraggableCore extends React.Component<Partial<DraggableCoreProps>, {}> {
65+
static defaultProps : DraggableCoreProps;
6866
}

typings/tsconfig.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@
22
"compilerOptions": {
33
"noEmit": true,
44
"jsx": "preserve",
5-
"strict": true
5+
"strict": true,
6+
"moduleResolution": "node",
7+
"baseUrl": ".",
8+
"paths": {
9+
"react-draggable": ["./index.d.ts"]
10+
}
611
},
712
"files": [
813
"index.d.ts",
914
"test.tsx"
1015
]
11-
}
16+
}

0 commit comments

Comments
 (0)