From 270933152e3b6ebbc914f2cb0aeae016bff46efb Mon Sep 17 00:00:00 2001 From: Mike Deverell Date: Sat, 20 Feb 2021 17:08:53 -0500 Subject: [PATCH 1/2] Prefer `import * as` for imports whose types are re-exported Fixes #7741 Using `import React from 'react'` causes issues when the import makes its way into the d.ts file. Users without `esModuleInterop: true` or `allowSyntheticDefaultImports: true` (or `skipLibCheck: true`) in their tsconfig files will get errors from typescript about not being able to default-import using that syntax. This PR fixes the specific imports that would cause issues due to their types being re-exported in `@apollo/client`'s types. --- src/link/persisted-queries/__tests__/react.tsx | 4 ++-- src/react/components/Mutation.tsx | 2 +- src/react/components/Query.tsx | 2 +- src/react/components/Subscription.tsx | 2 +- src/react/context/ApolloConsumer.tsx | 2 +- src/react/context/ApolloContext.ts | 2 +- src/react/context/ApolloProvider.tsx | 2 +- src/react/hoc/hoc-utils.tsx | 2 +- src/react/hoc/mutation-hoc.tsx | 2 +- src/react/hoc/query-hoc.tsx | 2 +- src/react/hoc/subscription-hoc.tsx | 2 +- src/react/hoc/withApollo.tsx | 2 +- src/react/hooks/useApolloClient.ts | 2 +- src/react/ssr/getDataFromTree.ts | 2 +- src/utilities/testing/mocking/MockedProvider.tsx | 2 +- 15 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/link/persisted-queries/__tests__/react.tsx b/src/link/persisted-queries/__tests__/react.tsx index 5c458cd59e1..a9595a1b1ac 100644 --- a/src/link/persisted-queries/__tests__/react.tsx +++ b/src/link/persisted-queries/__tests__/react.tsx @@ -1,5 +1,5 @@ -import React from 'react'; -import ReactDOM from 'react-dom/server'; +import * as React from 'react'; +import * as ReactDOM from 'react-dom/server'; import gql from 'graphql-tag'; import { print } from 'graphql'; import { sha256 } from 'crypto-hash'; diff --git a/src/react/components/Mutation.tsx b/src/react/components/Mutation.tsx index bd2ed3bb83d..0a1f7569039 100644 --- a/src/react/components/Mutation.tsx +++ b/src/react/components/Mutation.tsx @@ -1,4 +1,4 @@ -import PropTypes from 'prop-types'; +import * as PropTypes from 'prop-types'; import { OperationVariables } from '../../core'; import { MutationComponentOptions } from './types'; diff --git a/src/react/components/Query.tsx b/src/react/components/Query.tsx index f875e3d7d32..ee7b79c3253 100644 --- a/src/react/components/Query.tsx +++ b/src/react/components/Query.tsx @@ -1,4 +1,4 @@ -import PropTypes from 'prop-types'; +import * as PropTypes from 'prop-types'; import { OperationVariables } from '../../core'; import { QueryComponentOptions } from './types'; diff --git a/src/react/components/Subscription.tsx b/src/react/components/Subscription.tsx index c7962dddbd3..696c201936f 100644 --- a/src/react/components/Subscription.tsx +++ b/src/react/components/Subscription.tsx @@ -1,4 +1,4 @@ -import PropTypes from 'prop-types'; +import * as PropTypes from 'prop-types'; import { OperationVariables } from '../../core'; import { SubscriptionComponentOptions } from './types'; diff --git a/src/react/context/ApolloConsumer.tsx b/src/react/context/ApolloConsumer.tsx index 97316113c1b..c6ba6fffdc2 100644 --- a/src/react/context/ApolloConsumer.tsx +++ b/src/react/context/ApolloConsumer.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import * as React from 'react'; import { invariant } from 'ts-invariant'; import { ApolloClient } from '../../core'; diff --git a/src/react/context/ApolloContext.ts b/src/react/context/ApolloContext.ts index 1fac5bc5c9d..9e899297881 100644 --- a/src/react/context/ApolloContext.ts +++ b/src/react/context/ApolloContext.ts @@ -1,4 +1,4 @@ -import React from 'react'; +import * as React from 'react'; import { ApolloClient } from '../../core'; import { canUseWeakMap } from '../../utilities'; diff --git a/src/react/context/ApolloProvider.tsx b/src/react/context/ApolloProvider.tsx index adc6d66dd3a..5f678db8c91 100644 --- a/src/react/context/ApolloProvider.tsx +++ b/src/react/context/ApolloProvider.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import * as React from 'react'; import { invariant } from 'ts-invariant'; import { ApolloClient } from '../../core'; diff --git a/src/react/hoc/hoc-utils.tsx b/src/react/hoc/hoc-utils.tsx index 1a80dd6d151..58266adcc3a 100644 --- a/src/react/hoc/hoc-utils.tsx +++ b/src/react/hoc/hoc-utils.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import * as React from 'react'; import { invariant } from 'ts-invariant'; import { OperationVariables } from '../../core'; import { IDocumentDefinition } from '../parser'; diff --git a/src/react/hoc/mutation-hoc.tsx b/src/react/hoc/mutation-hoc.tsx index 5159753e678..6f81396d664 100644 --- a/src/react/hoc/mutation-hoc.tsx +++ b/src/react/hoc/mutation-hoc.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import * as React from 'react'; import { DocumentNode } from 'graphql'; import hoistNonReactStatics from 'hoist-non-react-statics'; diff --git a/src/react/hoc/query-hoc.tsx b/src/react/hoc/query-hoc.tsx index 428a64714d9..7eebb07ad26 100644 --- a/src/react/hoc/query-hoc.tsx +++ b/src/react/hoc/query-hoc.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import * as React from 'react'; import { DocumentNode } from 'graphql'; import hoistNonReactStatics from 'hoist-non-react-statics'; diff --git a/src/react/hoc/subscription-hoc.tsx b/src/react/hoc/subscription-hoc.tsx index 906d14a905f..d7b222ee146 100644 --- a/src/react/hoc/subscription-hoc.tsx +++ b/src/react/hoc/subscription-hoc.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import * as React from 'react'; import { DocumentNode } from 'graphql'; import hoistNonReactStatics from 'hoist-non-react-statics'; diff --git a/src/react/hoc/withApollo.tsx b/src/react/hoc/withApollo.tsx index 9b6422b0ef1..15fa8db2b27 100644 --- a/src/react/hoc/withApollo.tsx +++ b/src/react/hoc/withApollo.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import * as React from 'react'; import hoistNonReactStatics from 'hoist-non-react-statics'; import { invariant } from 'ts-invariant'; diff --git a/src/react/hooks/useApolloClient.ts b/src/react/hooks/useApolloClient.ts index 52390348a0a..461635cab7f 100644 --- a/src/react/hooks/useApolloClient.ts +++ b/src/react/hooks/useApolloClient.ts @@ -1,4 +1,4 @@ -import React from 'react'; +import * as React from 'react'; import { invariant } from 'ts-invariant'; import { ApolloClient } from '../../core'; diff --git a/src/react/ssr/getDataFromTree.ts b/src/react/ssr/getDataFromTree.ts index 9d639827a38..8664b08e98d 100644 --- a/src/react/ssr/getDataFromTree.ts +++ b/src/react/ssr/getDataFromTree.ts @@ -1,4 +1,4 @@ -import React from 'react'; +import * as React from 'react'; import { getApolloContext } from '../context'; import { RenderPromises } from './RenderPromises'; diff --git a/src/utilities/testing/mocking/MockedProvider.tsx b/src/utilities/testing/mocking/MockedProvider.tsx index 5612a0f53c5..7168bb2159f 100644 --- a/src/utilities/testing/mocking/MockedProvider.tsx +++ b/src/utilities/testing/mocking/MockedProvider.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import * as React from 'react'; import { ApolloClient, DefaultOptions } from '../../../core'; import { InMemoryCache as Cache } from '../../../cache'; From f3ef1c97628da551d5a3f27bb00ea4cd93771c87 Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Fri, 5 Mar 2021 12:41:24 -0500 Subject: [PATCH 2/2] Mention PR #7742 in CHANGELOG.md. --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 21b09c1d7d2..a1b5a5b7e1e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,9 @@ TBD - Allow `merge: true` field policy to merge `Reference` objects with non-normalized objects, and vice-versa.
[@benjamn](https://github.com/benjamn) in [#7778](https://github.com/apollographql/apollo-client/pull/7778) +- Prefer `import * as namepace ...` for imports whose types are re-exported (and thus may appear in `.d.ts` files).
+ [@devrelm](https://github.com/devrelm) in [#7742](https://github.com/apollographql/apollo-client/pull/7742) + ### Documentation TBD