TypeChain icon indicating copy to clipboard operation
TypeChain copied to clipboard

Generated files have mixed imports from `ethers` umbrella package and `@ethersproject` sub-packages

Open sebastianst opened this issue 4 years ago • 3 comments

The moment a project imports from the umbrella ethers npm package, it already has (almost) all dependencies that can be individually imported via the @ethersproject sub-packages. E.g. my ERC20.d.ts file contains the following imports

import {
  ethers,
  EventFilter,
  Signer,
  BigNumber,
  BigNumberish,
  PopulatedTransaction,
  BaseContract,
  ContractTransaction,
  Overrides,
  CallOverrides,
} from "ethers";
import { BytesLike } from "@ethersproject/bytes";
import { Listener, Provider } from "@ethersproject/providers";
import { FunctionFragment, EventFragment, Result } from "@ethersproject/abi";

Note that bytes, providers and abi are imported as separate npm modules, even though they're contained in ethers. See, e.g. the README of bytes:

Most users will prefer to use the umbrella package, but for those with more specific needs, individual components can be imported.

So I propose that all @ethersproject imports are replaced by the equivalent ethers imports, saving some package dependencies.

sebastianst avatar Oct 29 '21 15:10 sebastianst

Why not use the individual subpackages for the sake of ESM and tree-shaking?

jalavosus avatar Nov 02 '21 13:11 jalavosus

I think realistically, most projects using typechain-generated code would already use ethers, in which case the @ethersproject imports would add unnecessary deps. Note also that the ethers folks themselves suggest to use ethers over @ethersproject in most cases.

Best would be to make this behavior configurable, using ethers by default.

sebastianst avatar Nov 02 '21 13:11 sebastianst

Configurable would be excellent, tbh.

jalavosus avatar Nov 02 '21 14:11 jalavosus