Skip to content

Commit

Permalink
Prefer import * as for imports whose types are re-exported (#7742)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
devrelm authored Mar 5, 2021
1 parent fd93923 commit 9fb964e
Show file tree
Hide file tree
Showing 16 changed files with 19 additions and 16 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ TBD
- Allow `merge: true` field policy to merge `Reference` objects with non-normalized objects, and vice-versa. <br/>
[@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). <br/>
[@devrelm](https://github.com/devrelm) in [#7742](https://github.com/apollographql/apollo-client/pull/7742)

### Documentation
TBD

Expand Down
4 changes: 2 additions & 2 deletions src/link/persisted-queries/__tests__/react.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
2 changes: 1 addition & 1 deletion src/react/components/Mutation.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import PropTypes from 'prop-types';
import * as PropTypes from 'prop-types';

import { OperationVariables } from '../../core';
import { MutationComponentOptions } from './types';
Expand Down
2 changes: 1 addition & 1 deletion src/react/components/Query.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import PropTypes from 'prop-types';
import * as PropTypes from 'prop-types';

import { OperationVariables } from '../../core';
import { QueryComponentOptions } from './types';
Expand Down
2 changes: 1 addition & 1 deletion src/react/components/Subscription.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import PropTypes from 'prop-types';
import * as PropTypes from 'prop-types';

import { OperationVariables } from '../../core';
import { SubscriptionComponentOptions } from './types';
Expand Down
2 changes: 1 addition & 1 deletion src/react/context/ApolloConsumer.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import * as React from 'react';
import { invariant } from 'ts-invariant';

import { ApolloClient } from '../../core';
Expand Down
2 changes: 1 addition & 1 deletion src/react/context/ApolloContext.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import * as React from 'react';
import { ApolloClient } from '../../core';
import { canUseWeakMap } from '../../utilities';

Expand Down
2 changes: 1 addition & 1 deletion src/react/context/ApolloProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import * as React from 'react';
import { invariant } from 'ts-invariant';

import { ApolloClient } from '../../core';
Expand Down
2 changes: 1 addition & 1 deletion src/react/hoc/hoc-utils.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
2 changes: 1 addition & 1 deletion src/react/hoc/mutation-hoc.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import * as React from 'react';
import { DocumentNode } from 'graphql';
import hoistNonReactStatics from 'hoist-non-react-statics';

Expand Down
2 changes: 1 addition & 1 deletion src/react/hoc/query-hoc.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import * as React from 'react';
import { DocumentNode } from 'graphql';
import hoistNonReactStatics from 'hoist-non-react-statics';

Expand Down
2 changes: 1 addition & 1 deletion src/react/hoc/subscription-hoc.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import * as React from 'react';
import { DocumentNode } from 'graphql';
import hoistNonReactStatics from 'hoist-non-react-statics';

Expand Down
2 changes: 1 addition & 1 deletion src/react/hoc/withApollo.tsx
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
2 changes: 1 addition & 1 deletion src/react/hooks/useApolloClient.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import * as React from 'react';
import { invariant } from 'ts-invariant';

import { ApolloClient } from '../../core';
Expand Down
2 changes: 1 addition & 1 deletion src/react/ssr/getDataFromTree.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import * as React from 'react';
import { getApolloContext } from '../context';
import { RenderPromises } from './RenderPromises';

Expand Down
2 changes: 1 addition & 1 deletion src/utilities/testing/mocking/MockedProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import * as React from 'react';

import { ApolloClient, DefaultOptions } from '../../../core';
import { InMemoryCache as Cache } from '../../../cache';
Expand Down

0 comments on commit 9fb964e

Please sign in to comment.