From e70b29ae64837e424f7279c95112fb6e420c4dcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claud=C3=A9ric=20Demers?= Date: Thu, 12 Sep 2024 10:33:40 -0400 Subject: [PATCH] Fix generics for manager passed to Entity --- .changeset/fix-generics.md | 6 ++++++ packages/abstract/src/core/entities/draggable/draggable.ts | 2 +- packages/abstract/src/core/entities/droppable/droppable.ts | 2 +- packages/dom/src/core/entities/draggable/draggable.ts | 5 ++++- packages/dom/src/core/entities/droppable/droppable.ts | 5 ++++- 5 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 .changeset/fix-generics.md diff --git a/.changeset/fix-generics.md b/.changeset/fix-generics.md new file mode 100644 index 00000000..bb92ca11 --- /dev/null +++ b/.changeset/fix-generics.md @@ -0,0 +1,6 @@ +--- +'@dnd-kit/abstract': patch +'@dnd-kit/dom': patch +--- + +Make sure the generic for `DragDropManager` is passed through to `Entity` so that the `manager` reference on classes extending `Entity` is strongly typed. diff --git a/packages/abstract/src/core/entities/draggable/draggable.ts b/packages/abstract/src/core/entities/draggable/draggable.ts index 01b83e2c..4ff9cf6a 100644 --- a/packages/abstract/src/core/entities/draggable/draggable.ts +++ b/packages/abstract/src/core/entities/draggable/draggable.ts @@ -17,7 +17,7 @@ export type DraggableStatus = 'idle' | 'dragging' | 'dropping'; export class Draggable< T extends Data = Data, U extends DragDropManager = DragDropManager, -> extends Entity { +> extends Entity { constructor( {modifiers, type, sensors, ...input}: Input, manager: U | undefined diff --git a/packages/abstract/src/core/entities/droppable/droppable.ts b/packages/abstract/src/core/entities/droppable/droppable.ts index f7d7a225..8b2a8983 100644 --- a/packages/abstract/src/core/entities/droppable/droppable.ts +++ b/packages/abstract/src/core/entities/droppable/droppable.ts @@ -20,7 +20,7 @@ export interface Input extends EntityInput { export class Droppable< T extends Data = Data, U extends DragDropManager = DragDropManager, -> extends Entity { +> extends Entity { constructor( {accept, collisionDetector, collisionPriority, type, ...input}: Input, manager: U | undefined diff --git a/packages/dom/src/core/entities/draggable/draggable.ts b/packages/dom/src/core/entities/draggable/draggable.ts index cdab0be0..ff10c6d5 100644 --- a/packages/dom/src/core/entities/draggable/draggable.ts +++ b/packages/dom/src/core/entities/draggable/draggable.ts @@ -19,7 +19,10 @@ export interface Input extends DraggableInput { modifiers?: Modifiers; } -export class Draggable extends AbstractDraggable { +export class Draggable extends AbstractDraggable< + T, + DragDropManager +> { constructor( { element, diff --git a/packages/dom/src/core/entities/droppable/droppable.ts b/packages/dom/src/core/entities/droppable/droppable.ts index 5e332f04..1052e89b 100644 --- a/packages/dom/src/core/entities/droppable/droppable.ts +++ b/packages/dom/src/core/entities/droppable/droppable.ts @@ -24,7 +24,10 @@ export interface Input element?: Element; } -export class Droppable extends AbstractDroppable { +export class Droppable extends AbstractDroppable< + T, + DragDropManager +> { constructor( {element, effects = () => [], ...input}: Input, manager: DragDropManager | undefined