I'm writing unit tests for an ERC20 token in TypeScript. I'm getting this error from TypeScript:
Argument of type 'HardhatEthersSigner' is not assignable to parameter
of type 'string | Signer | undefined'.
Here's my code:
import { assert, expect } from "chai";
import { deployments, ethers } from "hardhat";
import { MyToken } from "../../typechain-types";
import { SignerWithAddress } from "@nomicfoundation/hardhat-ethers/signers";
import { Signer } from "ethers";
const INITIAL_SUPPLY = 20;
describe("MyToken Unit Test", function () {
let myToken: MyToken;
let deployer:SignerWithAddress;
let userOne: SignerWithAddress;
beforeEach(async function () {
const accounts = await ethers.getSigners();
deployer = accounts[0];
userOne = accounts[1];
await deployments.fixture("all");
myToken = await ethers.getContract("MyToken", deployer);
});
.
.
.
});
I have tried typecasting from SignerWithAddress
to Signer
but it does not work. I also tried making deployer
a union type by using let deployer:Signer|SignerWithAddress;
but it doesn't work either.
So far the only solution I have is making the deployer
's type as any
but it's not a good practice.
Additional information:
Solidity compiler version: 0.8.21
Best Answer
Ran into this and then another issue related to the v6 migration. Once I installed ethers as a dependency (
yarn add -D ethers
), I was able to get this to work.