[Web] v3 typing and using handler data#3651
Conversation
91aad1d to
5837159
Compare
| type ResultEventType = GestureHandlerEvent<unknown> | GestureHandlerNativeEvent; | ||
| export interface ResultEvent<T extends ResultEventType = ResultEventType> | ||
| extends Record<string, T | number> { | ||
| nativeEvent: T; |
There was a problem hiding this comment.
Correct me if I'm wrong, but GestureHandlerEvent already has nativeEvent field (look here for context). In that case, we will have event type where it is possible to have nativeEvent.nativeEvent
There was a problem hiding this comment.
Also I find it quite confusing with this default value, wouldn't it be easier to read if we had just ResultEvent<T> and then pass either GestureHandlerEvent, GestureHandlerNativeEvent or TouchEvent?
There was a problem hiding this comment.
Correct me if I'm wrong, but GestureHandlerEvent already has nativeEvent
No, types in GestureHandlerEvent are wrappers on payload types defined here, and only add handlerData. Those types do not have nativeEvent field
Also I find it quite confusing with this default value
Ok, it was inspired by this. I thought that it would simplify the code as we would not have to write <unknown> everywhere. I don't have a strong preference, if you think it's better to add <unknown> i can change it.
There was a problem hiding this comment.
if you think it's better to add i can change it.
What do you think I should do? I feel that current solution is stronger typed, what I think is better
| this.propsRef!.current; | ||
|
|
||
| const touchEvent: ResultTouchEvent | undefined = | ||
| const touchEvent: ResultEvent<TouchEvent> | undefined = |
There was a problem hiding this comment.
Are you sure that TouchEvent will have correct fields and won't expose something that we do not provide?
There was a problem hiding this comment.
Yes, gestureTouchEvent defined here, on which TouchEvent is a union has the same fields as the old nativeTouchEvent defined within web/interfaces.
There was a problem hiding this comment.
Now when I think about it we could probably do the same for GestureHandlerNativeEvent, is there a reason why v2 redeclared those types for the web, when we already have similar types in commons?
EDIT: ok, nevermind they have conflicting type
Description
Changing web implementation to use v3 types with a proper
handlerDatafield.Test plan
check whether
handledDatais a proper field ofnativeEventwhen usingNativeDetector.