Skip to content

Commit 8ffaea9

Browse files
committed
Add comment
1 parent e6a908f commit 8ffaea9

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

packages/react-native-gesture-handler/src/v3/types/ReanimatedTypes.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,19 @@ export type SharedValue<Value = unknown> = {
1010
) => void;
1111
};
1212

13+
// Utility type that turns `T` into `T | SharedValue<T>`. `P` is used to avoid splitting union types.
1314
export type SharedValueOrT<T, P = never> =
15+
// We always want to get `T` in the resulting type.
1416
| T
17+
// If `T` is one of the types in `P`, we don't want to split the union, so we return SharedValue<T>.
1518
| (Exclude<T, undefined> extends P
1619
? SharedValue<Exclude<T, undefined>>
17-
: T extends any
18-
? SharedValue<Exclude<T, undefined>>
19-
: SharedValue<Exclude<T, undefined>>);
20+
: // If `T` is not in `P`, we want to split the union and wrap each member with SharedValue, using Distributive Conditional Types (https://www.typescriptlang.org/docs/handbook/2/conditional-types.html#distributive-conditional-types).
21+
T extends any
22+
? // Wrap each member of the union with SharedValue.
23+
SharedValue<Exclude<T, undefined>>
24+
: // If `T` is only one type, just return SharedValue<T>.
25+
SharedValue<Exclude<T, undefined>>);
2026

2127
// Utility type that decides whether to recurse for objects or apply SharedValue directly.
2228
export type WithSharedValue<T, P = never> = T extends object

0 commit comments

Comments
 (0)