Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The CompilerOutputContract type doesn't include fields for optional outputs #4425

Open
kalote opened this issue Sep 28, 2023 · 2 comments
Open
Assignees
Labels
status:ready This issue is ready to be worked on type:improvement

Comments

@kalote
Copy link

kalote commented Sep 28, 2023

Version of Hardhat

2.13.0

What happened?

Hello!

I'm trying to get the storageLayout information from the buildInfo. I'm using hardhat in typescript. I changed my hardhat.config.ts with this:

const config: HardhatUserConfig = {
  solidity: {
    version: '0.8.17',
    settings: {
      optimizer: {
        enabled: true,
        runs: 1000,
      },
      outputSelection: {
        '*': {
          '*': ['storageLayout'],
        },
      },
    },
  },
};

But i end up with a TS issue when trying to access the storageLayout property:

(await artifacts.getBuildInfo('contracts/CustomToken.sol:CustomToken'))?.output.contracts['contracts/CustomToken.sol'].CustomToken.storageLayout
Property 'storageLayout' does not exist on type 'CompilerOutputContract'.ts(2339)

Any idea?
Thank you!

Minimal reproduction steps

  • Create a TS hardhat project
  • Add the custom compiler options:
const config: HardhatUserConfig = {
  solidity: {
    version: '0.8.17',
    settings: {
      optimizer: {
        enabled: true,
        runs: 1000,
      },
      outputSelection: {
        '*': {
          '*': ['storageLayout'],
        },
      },
    },
  },
};
  • Create a basic contract
  • Try to access the storageLayout using
(await artifacts.getBuildInfo('contracts/CustomToken.sol:CustomToken'))?.output.contracts['contracts/CustomToken.sol'].CustomToken.storageLayout

Search terms

storage layout output selection

@kalote
Copy link
Author

kalote commented Oct 6, 2023

Any news?

@fvictorio
Copy link
Member

Hey @kalote, sorry for not responding sooner.

Sadly the only workaround here is to cast (await artifacts.getBuildInfo('contracts/CustomToken.sol:CustomToken'))?.output.contracts['contracts/CustomToken.sol'].CustomToken to any (or to an expanded type that includes storageLayout).

As a long term solution, we should use a better type for CompilerOutputContract, which includes other things as optional properties, since they could be added by the user, like in your case.

@fvictorio fvictorio added type:improvement status:ready This issue is ready to be worked on and removed status:triaging labels Oct 17, 2023
@fvictorio fvictorio changed the title Customized outputSelection doesn't update types The CompilerOutputContract type doesn't include fields for optional outputs Oct 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:ready This issue is ready to be worked on type:improvement
Projects
Status: Backlog
Development

No branches or pull requests

3 participants