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

fix(TS): ITextBehaviour enterEditing type #9075

Merged
merged 2 commits into from
Jul 8, 2023

Conversation

jiayihu
Copy link
Contributor

@jiayihu jiayihu commented Jul 7, 2023

Very very minor change. The event was type correctly: 'editing:entered': never | { e: TPointerEvent }, but the method required e to be defined.

Copy link
Contributor

@ShaMan123 ShaMan123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense
Needed when calling the method imperatively

@ShaMan123
Copy link
Contributor

We cab still pass the same object to the event because the fire method passes an empty object anyways

@jiayihu
Copy link
Contributor Author

jiayihu commented Jul 8, 2023

We cab still pass the same object to the event because the fire method passes an empty object anyways

The type would be different, the passed object would be of type { e: TPointerEvent | undefined }, whereas the event has type never | { e: TPointerEvent }

@ShaMan123
Copy link
Contributor

It doesn't matter

listenersForEvent[i].call(this, options || {});

@jiayihu
Copy link
Contributor Author

jiayihu commented Jul 8, 2023

{ e: undefined } is not the same as undefined. I was also referring to the type, which for editing:entered is types as 'editing:entered': never | { e: TPointerEvent } so you can't pass { e: undefined }

@ShaMan123 ShaMan123 changed the title TS: Fix ITextBehaviour enterEditing type fix(TS): ITextBehaviour enterEditing type Jul 8, 2023
@ShaMan123 ShaMan123 merged commit d0d98db into fabricjs:master Jul 8, 2023
1 of 2 checks passed
@ShaMan123
Copy link
Contributor

I know
I wrote the type
fire passes an object anyways so it can be { e?: TPointerEvent } instead of never | { e: TPointerEvent }

@ShaMan123
Copy link
Contributor

ShaMan123 commented Jul 8, 2023

I am meticulous only because I was instructed to keep type PRs pure
I know it can be annoying

@jiayihu jiayihu deleted the ts/enter-editing-2 branch July 8, 2023 14:27
@jiayihu
Copy link
Contributor Author

jiayihu commented Jul 8, 2023

fire passes an object anyways so it can be { e?: TPointerEvent } instead of never | { e: TPointerEvent }

Aahh so you were suggesting to change the event type to be { e?: TPointerEvent }? In that case, you need to be clear in your comments, most of the time I can hardly understand what you mean you exactly 😄

I am meticulous only because I was instructed to keep type PRs pure

For instance, here by "pure" you mean keeping the PR type-only without runtime JS changes? I can't every time have to guess what's in your mind. For me "pure" has a different meaning, typically associated with "pure functions", i.e. without side effects.

@ShaMan123
Copy link
Contributor

I looked again at the code
There are other instances of this and they use an optional event so this should as well

interface CanvasSelectionEvents {
'selection:created': Partial<TEvent> & {
selected: FabricObject[];
};
'selection:updated': Partial<TEvent> & {
selected: FabricObject[];
deselected: FabricObject[];
};
'before:selection:cleared': Partial<TEvent> & {
deselected: FabricObject[];
};
'selection:cleared': Partial<TEvent> & {
deselected: FabricObject[];
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants