Skip to content

Commit 4317c98

Browse files
committed
refactor: fix types for useOpenLayersEvents
1 parent 3e1147a commit 4317c98

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

src/composables/useOpenLayersEvents.ts

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ import {
55
type ComputedRef,
66
isRef,
77
inject,
8+
type ShallowRef,
89
} from "vue";
9-
import type { ObjectEvent } from "ol/Object";
10+
import type BaseObject from "ol/Object";
11+
import type { EventTypes } from "ol/Observable";
1012

1113
export const COMMON_EVENTS = ["change", "error", "propertychange"];
1214

@@ -30,29 +32,21 @@ export const FEATURE_EVENTS = [
3032
"removefeature",
3133
];
3234

33-
// Define a generic type for the event callback
34-
type EventCallback = (event: ObjectEvent) => void;
35-
36-
// Define the generic type parameter for the OpenLayers feature
37-
type OpenLayersFeature = {
38-
on: (event: string, callback: EventCallback) => void;
39-
un: (event: string, callback: EventCallback) => void;
40-
} & unknown;
41-
4235
// Define the composable function
4336
export function useOpenLayersEvents(
4437
feature:
45-
| OpenLayersFeature
46-
| Ref<OpenLayersFeature>
47-
| ComputedRef<OpenLayersFeature>,
38+
| BaseObject
39+
| Ref<BaseObject>
40+
| ShallowRef<BaseObject>
41+
| ComputedRef<BaseObject>,
4842
eventNames: string[],
4943
) {
5044
const instance = getCurrentInstance();
5145
const globalOptions = inject("ol-options");
5246

5347
onMounted(() => {
54-
[...COMMON_EVENTS, ...eventNames].forEach((eventName) => {
55-
let unwrappedFeature: Pick<OpenLayersFeature, "on">;
48+
([...COMMON_EVENTS, ...eventNames] as EventTypes[]).forEach((eventName) => {
49+
let unwrappedFeature: Pick<BaseObject, "on">;
5650

5751
if (!isRef(feature)) {
5852
unwrappedFeature = feature;

0 commit comments

Comments
 (0)