Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typing definition is incompleted, cannot type SelectionEvent function. #95

Closed
maxime4000 opened this issue Feb 25, 2021 · 6 comments
Closed
Labels
bug Something isn't working

Comments

@maxime4000
Copy link

maxime4000 commented Feb 25, 2021

What is the problem?

Updating from 1.7.1 to 2.0.0, I had to fix my typescript code with the new SelectionArea instead of Selection, but before I was using Selection.SelectionEvent to type my onStart/onMove/onStop function, but right now, only SelectionArea is available as typing... Not SelectionArea.SelectionEvent.
I try to import :
import { SelectionEvent } from "@simonwep/selection-js/src/types";
but I get :
Cannot find module '@utils' or its corresponding type declarations. TS2307

What is the expected behavior?

Something like this would work :
import SelectionArea, { SelectionEvent, ChangedElements, SelectionStore, ... } from "@simonwep/selection-js";

Your environment:

Version (SelectionArea.version): 2.0.0
Browser:  Typescript compiler ?
OS:  Windows
@simonwep
Copy link
Owner

simonwep commented Feb 25, 2021

This is expected, v2 is a major release with breaking changes. See semver.
The type-definition cannot be incomplete since the whole library is now written in TS and type-definitions are automatically generated from the source-code.

@simonwep simonwep added the question Further information is requested label Feb 25, 2021
@maxime4000
Copy link
Author

But how would you import the type SelectionEvent ?

@maxime4000
Copy link
Author

The problems I suppose is index.ts is only exporting SelectionArea and nothing else.

@maxime4000
Copy link
Author

maxime4000 commented Feb 25, 2021

I think you misunderstood what I mean @simonwep. It's not because your code is in typescript that all the typing definition can be imported. If your index.ts is not exporting every types, the definiton of those type are not usable. Right now, only SelectionArea is exported.

SelectionArea is exported because of this line :

  • File : src/index.ts:9 : export default class SelectionArea extends EventTarget<SelectionEvents> {
  • Typing File : selection.min.d.ts:199 : export { SelectionArea as default };

Sure there is a work around here which I just try out now :

const selection = new SelectionArea({...});
selection.on("start", ({store, event}) => {...}); // this line work because typescript imply SelectionEvent

But if you use it like below, you have to import typing which isn't accessible anymore on v2.

const selection = new SelectionArea({...});
const onStart = ({store, event}) => {...}; // store and event are type any
selection.on("start", onStart);

@simonwep
Copy link
Owner

Allright, gotchya - yes you're right. Sorry, they're not exported anymore - that's a problem.

@simonwep simonwep reopened this Feb 25, 2021
@simonwep simonwep added enhancement bug Something isn't working and removed question Further information is requested enhancement labels Feb 25, 2021
@simonwep
Copy link
Owner

Fixed and available in v2.0.1 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants