In my current project, I have implemented the following code snippet to create a select interaction, integrate it into a map, and execute certain actions when a feature is selected or deselected:
const select: Select = new Select({
hitTolerance: 5,
multi: false,
condition: singleClick
});
this.map.addInteraction(select);
select.on('select', (se: SelectEvent) => {
console.log('select fired: ', se);
// carry out operations using se...
});
The challenge I am facing is that I am utilizing TypeScript and aiming to fully leverage type-checking, but I am unsure about how to import SelectEvent
. As a result, the code mentioned above does not pass type-checking and displays the error:
`TS2304: Cannot find name 'SelectEvent'`
When trying:
import {SelectEvent} from 'ol/interaction';
I encounter:
TS2305: Module '"../../../node_modules/@types/ol/interaction"' has no exported member 'SelectEvent'.
Examining the OpenLayers segment of my package.json
reveals:
$ npm ls --depth=0 | grep -i ol | grep -v polyfill
├── @siedlerchr/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="85f1fcf5e0f6a8eae9a8e0fdf1c5b4abb5abb5">[email protected]</a> (git+https://github.com/Siedlerchr/types-ol-ext.git#ec995982b2ba7aa4d415e67a350ec4b9f841ea37)
├── @types/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="47282b077169736975">[email protected]</a>
├── <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="fd9291bdcbd3c9d3ce">[email protected]</a>
├── <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1d7271307865695d2e332c332c28">[email protected]</a>
Upon searching for the SelectEvent
type, I came across:
node_modules/@types/ol/interaction/Select.d.ts:declare class SelectEvent extends BaseEvent {
.. yet I'm uncertain about how to correctly import this declaration (as it doesn't appear to be exported initially).