From da93d124d281d534300f607ac4fd9375df76728d Mon Sep 17 00:00:00 2001 From: Cameron Knight Date: Mon, 21 May 2018 07:12:36 -0700 Subject: [PATCH] [@types/react-relay] QueryRendererProps["query"] can be null/undefined --- types/react-relay/index.d.ts | 3 ++- types/react-relay/test/react-relay-tests.tsx | 23 +++++++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/types/react-relay/index.d.ts b/types/react-relay/index.d.ts index 35a194b0e7..f87ce26356 100644 --- a/types/react-relay/index.d.ts +++ b/types/react-relay/index.d.ts @@ -4,6 +4,7 @@ // Matt Martin // Eloy DurĂ¡n // Nicolas Pirotte +// Cameron Knight // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.6 @@ -76,7 +77,7 @@ export const graphql: GraphqlInterface; export interface QueryRendererProps { cacheConfig?: RelayRuntimeTypes.CacheConfig; environment: RelayRuntimeTypes.Environment; - query: RelayRuntimeTypes.GraphQLTaggedNode; + query?: RelayRuntimeTypes.GraphQLTaggedNode | null; render(readyState: ReadyState): React.ReactElement | undefined | null; variables: RelayRuntimeTypes.Variables; rerunParamExperimental?: RelayRuntimeTypes.RerunParam; diff --git a/types/react-relay/test/react-relay-tests.tsx b/types/react-relay/test/react-relay-tests.tsx index cc25f5f368..bf3e2d1475 100644 --- a/types/react-relay/test/react-relay-tests.tsx +++ b/types/react-relay/test/react-relay-tests.tsx @@ -28,16 +28,16 @@ const modernEnvironment = new Environment({ network, store }); // ~~~~~~~~~~~~~~~~~~~~~ // Modern QueryRenderer // ~~~~~~~~~~~~~~~~~~~~~ -const MyQueryRenderer = (props: { name: string }) => ( +const MyQueryRenderer = (props: { name: string, show: boolean }) => ( ( /> ); +const MyEmptyQueryRenderer = () => ( + { + if (error) { + return
{error.message}
; + } else if (props) { + throw new Error('This code path should never be hit'); + } + return
Loading
; + }} + /> +); + // ~~~~~~~~~~~~~~~~~~~~~ // Modern RefetchContainer // ~~~~~~~~~~~~~~~~~~~~~