Skip to content

Commit 83110b2

Browse files
authored
[General] Fix DiagonalDirections type (#3795)
## Description It seems like TypeScript isn't treating an expression where every node is `const` as `const`: ```ts const a = 1; // a: 1 const b = 2; // b: 2 const c = a + b; // c: number ``` This caused `DiagonalDirections` type to be a number instead of a union of consts. ## Test plan Check the inferred type of `DiagonalDirections`
1 parent 99daffa commit 83110b2

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

packages/react-native-gesture-handler/src/Directions.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,27 @@ const LEFT = 2;
33
const UP = 4;
44
const DOWN = 8;
55

6+
// Those need to be constant values rather than expressions for TypeScript not
7+
// to type them as 'number'.
8+
const UP_RIGHT = 5; // UP | RIGHT
9+
const DOWN_RIGHT = 9; // DOWN | RIGHT
10+
const UP_LEFT = 6; // UP | LEFT
11+
const DOWN_LEFT = 10; // DOWN | LEFT
12+
613
// Public interface
714
export const Directions = {
8-
RIGHT: RIGHT,
9-
LEFT: LEFT,
10-
UP: UP,
11-
DOWN: DOWN,
15+
RIGHT,
16+
LEFT,
17+
UP,
18+
DOWN,
1219
} as const;
1320

1421
// Internal interface
1522
export const DiagonalDirections = {
16-
UP_RIGHT: UP | RIGHT,
17-
DOWN_RIGHT: DOWN | RIGHT,
18-
UP_LEFT: UP | LEFT,
19-
DOWN_LEFT: DOWN | LEFT,
23+
UP_RIGHT,
24+
DOWN_RIGHT,
25+
UP_LEFT,
26+
DOWN_LEFT,
2027
} as const;
2128

2229
// eslint-disable-next-line @typescript-eslint/no-redeclare -- backward compatibility; it can be used as a type and as a value

0 commit comments

Comments
 (0)