DefinitelyTyped/types/react-relay
Janic Duplessis 82240e5032 [react-relay] Handle all variations of nullability and arrays for useFragment (#40167)
* [react-relay] Handle all variations of nullability and arrays for `useFragment`

The previous implementation did not detect nullability properly and also missed handling 2 cases for arrays (`[X]!` and `[X!]`). 

To do this we always use the `TKey` generic parameter which should be the exact type of `XFragment_foo$key`. Nullability is determined by the type of the `fragmentRef` parameter (the fragment type doesn't actually encode nullability anyway). For arrays the key type will already be an array so we have to handle then slightly differently. We have one overload for each possible combinaison of nullability (2 for regular fields, 4 for arrays).

- Type `ReturnType` is the non-nullable type for a regular field key. Nullability is added on usage.
- Type `NonNullableArrayReturnType` is the non-nullable array type for an array field key. Nullability of the **field** is added on usage.
- Type `NullableArrayReturnType` is the nullable array type for an array field key. Nullability of the **field** is added on usage.

Tested all 6 possible combinaisons of array / nullability with `useFragment<XFragment_foo$key>(...)` and validated that the ts type returned matched the nullability / and whether it's an array of the schema.

* Fix array types

* Add tests, fix nullable array types

* Simplify test key type

* Remove support for array of nullable elements

* Fix lint in example
2019-11-07 12:20:10 +01:00
..
lib [react-relay] Handle all variations of nullability and arrays for useFragment (#40167) 2019-11-07 12:20:10 +01:00
test [react-relay] Handle all variations of nullability and arrays for useFragment (#40167) 2019-11-07 12:20:10 +01:00
hooks.d.ts
index.d.ts
tsconfig.json
tslint.json