Open Tlepel opened 1 year ago
I'll look into it this week. This would certainly be beneficial to our app as well.
I think this would be a simple change that wouldn't break backwards functionality if you did something like this:
export interface DndDropEvent<T = any, U = any> {
event: DragEvent;
dropEffect: DropEffect;
isExternal: boolean;
data?: T;
index?: number;
type?: U;
}
Right now this is what I'm doing to get stricter typing
import { DndDropEvent } from 'ngx-drag-drop'
interface MyDropEvent<T = any, U = any> extends DndDropEvent {
data: T; // made this required for our app
type?: U;
}
Is your feature request related to a problem? Please describe. We're currently in the process of strictly typing our templates, and we have to make an ugly workaround for the
DndDropEvent
since it'sdata
property is typedany
instead of a genericT
.Describe the solution you'd like Being able to assume a type in handler-functions, such as
onDrop(event: DndDropEvent<MyDataType>)
, in whichevent
gets the propertydata: MyDataType
instead ofdata: any
.Describe alternatives you've considered An alternative would be to use the
type
property (which is typed withany
as well) and a switch-case to check whether or not we can useas
to convert the data to the correct type. Another alternative I've considered is to create interfaces that have the exact properties we have on the relevant types, and performinstanceof
checks.We can't use Angular Material Drag & Drop for dragging, since the lists are nested and it doesn't support nested lists. However, Angular Material does have the option to type the
data
property of the event.