zama-ai / fhevm

A Solidity library for interacting with an fhEVM blockchain.
Other
395 stars 76 forks source link

Fix Typescript type checker errors #582

Open silasdavis opened 3 days ago

silasdavis commented 3 days ago

Description

Currently there are a huge number of Typescript errors emitted by:

tsc --noEmit

Expected Behavior

There should be no Typescript compiler errors

Screenshots / Logs

❯ pnpm tsc --noEmit

... SNIP ...

Found 337 errors in 43 files.

Errors  Files
     1  hardhat.config.ts:22
     1  tasks/etherscanVerify.ts:5
     7  tasks/taskDeploy.ts:9
     1  tasks/taskGatewayRelayer.ts:111
     7  tasks/upgradeProxy.ts:2
    28  test/asyncDecrypt.ts:6
     1  test/blindAuction/BlindAuction.fixture.ts:4
     3  test/blindAuction/BlindAuction.ts:20
    87  test/coprocessorUtils.ts:2
     1  test/encryptedERC20/EncryptedERC20.fixture.ts:3
     4  test/fhevmjsMocked.ts:403
     1  test/governor/Comp.fixture.ts:3
     1  test/governor/Comp.ts:18
     2  test/governor/GovernorZama.fixture.ts:3
     2  test/governor/GovernorZama.ts:16
     1  test/identity/ERC20Rules.fixture.ts:3
     1  test/identity/compliantERC20.fixture.ts:3
     4  test/identity/compliantERC20.ts:26
     1  test/identity/identityRegistry.fixture.ts:3
     1  test/identity/identityRegistry.ts:18
     3  test/instance.ts:8
    11  test/payments/payments.ts:45
     1  test/rand/Rand.fixture.ts:3
    11  test/rand/Rand.ts:56
     2  test/regressions/Regression1.ts:6
     5  test/signers.ts:41
     1  test/tfheOperations/manual.ts:4
    11  test/tfheOperations/tfheOperations1.ts:4
    11  test/tfheOperations/tfheOperations10.ts:4
    11  test/tfheOperations/tfheOperations11.ts:4
    11  test/tfheOperations/tfheOperations12.ts:4
    11  test/tfheOperations/tfheOperations13.ts:4
    11  test/tfheOperations/tfheOperations2.ts:4
    11  test/tfheOperations/tfheOperations3.ts:4
    11  test/tfheOperations/tfheOperations4.ts:4
    11  test/tfheOperations/tfheOperations5.ts:4
    11  test/tfheOperations/tfheOperations6.ts:4
    11  test/tfheOperations/tfheOperations7.ts:4
    11  test/tfheOperations/tfheOperations8.ts:4
    11  test/tfheOperations/tfheOperations9.ts:4
     2  test/types.ts:1
     1  test/upgrades/upgrades.ts:4
     2  test/utils.ts:5

Environment Information

Fill in the relevant environment details where the issue was observed:

Steps Taken to Debug

Most of these errors would be straight-forward to address by making better use of:

Happy to follow-up with some fixes for these.

Trickier to resolve is:

test/instance.ts:8:8 - error TS2307: Cannot find module 'fhevmjs' or its corresponding type declarations.
  There are types at '/home/silas/code/fhevm/node_modules/fhevmjs/lib/web.d.ts', but this result could not be resolved under your current 'moduleResolution' setting. Consider updating to 'node16', 'nodenext', or 'bundler'.

8 } from 'fhevmjs';

I'm not entirely clear why these types are not resolved but it should be possible for fhevmjs to provide them in a manner consumable by NodeNext/Bundler configurations and Node16. Upgrading module/moduleResolution is not practical because it will pull in many more incompatibilities (e.g. with hardhat)

silasdavis commented 3 days ago

A hack that appears to work here:

Merge into tsconfig.json

{
   "compilerOptions": {
      "typeRoots": ["./node_modules/@types", "**/node_modules/@types", "./@types"]
    }
}

Add to root of repo: @types/fhevmjs/index.d.ts:

export * from "fhevmjs/web";

A fix on fhevmjs is preferable.

silasdavis commented 3 days ago

Once you add the above incidentally you can see lots of type mismatches in ./test/instance.ts and associated mocks

silasdavis commented 2 days ago

Made a start in #583