Skip to content

Commit

Permalink
Switch to import = for ws types, since @types/ws uses export =.
Browse files Browse the repository at this point in the history
While it would be perfectly fine to use `import *` in this particular case,
we've moved away from the star-import pattern in this repository, instead
preferring the `esModuleInterop` compiler option which seems to be the
direction that TypeScript is moving as it's now the default with `tsc --init`.

TypeScript clearly lost its battle with `import *` which many consider to
have been an incorrect direction in the first place.  Some build tools won't
work with star imports, and using them can make some optimizations more
difficult.  By avoiding this pattern here, hopefully we'll avoid moving back
in that direction inadvertently.

Here's a read I found at one point which roughly explains:

https://itnext.io/great-import-schism-typescript-confusion-around-imports-explained-d512fc6769c2
  • Loading branch information
abernix committed Feb 20, 2019
1 parent 6905e6d commit c1607cb
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/apollo-server-core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import {
GraphQLParseOptions,
} from 'graphql-tools';
import { ConnectionContext } from 'subscriptions-transport-ws';
import * as WebSocket from 'ws';
// The types for `ws` use `export = WebSocket`, so we'll use the
// matching `import =` to bring in its sole export.
import WebSocket = require('ws');
import { GraphQLExtension } from 'graphql-extensions';
export { GraphQLExtension } from 'graphql-extensions';

Expand Down

0 comments on commit c1607cb

Please sign in to comment.