question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Broken syntax for generated types

See original GitHub issue

I am migrating a truffle project to hardhat/typechain/trufflev5 and apparently typechain is generating types with a broken typescript syntax - the contracts should be compiled correctly as I am able to do that both in a truffle and openzeppelin environment

SyntaxError: '{' expected. (25:37)
  23 |   
  24 |
> 25 |   export interface Committed_address[] {
     |                                     ^
  26 |     name: "Committed"
  27 |     args: {
  28 |     whitelist : (string)[], 

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
derekarendscommented, Nov 27, 2021

@krzkaczor Using the sample provided by Riccardo it looks like when there are event overloads and those events have array args the code outputs invalid naming. This doesn’t happen with ethers-v5 because it looks like for ethers we do not try to write both event interfaces in the overloading contract.

From sample:

contract WhitelistedWithGovernance is Whitelisted {
    event Committed(address[] whitelist);
}
contract WhitelistedWithGovernanceAndChangableTimelock is WhitelistedWithGovernance {
    event Committed(uint256 timelock);
}

These contracts for truffle-v5 and for web3-v1 create WhitelistedWithGovernance.d.ts fine but when it attempts to create WhitelistedWithGovernanceAndChangableTimelock.d.ts file containing overloaded interfaces it errors:

export interface Committed_uint256 { ...

export interface Committed_address[] { ...

I wasn’t sure if both interfaces were to be expected or if we should have both interfaces in the types file and it will need to be renamed to something like Committed_address_array.

I am willing to create a PR for this just wasn’t sure what is expected.

1reaction
krzkaczorcommented, Nov 30, 2021

@derekarends thanks for investigating this!

I think that we should generate names with explicit names like: Committed_address_array, when conflicting events are detected. We already do something like this for function signatures. And there is even a flag to always generate such overrides: --always-generate-overloads. I think you can use the same flag to control this behavior.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Source Generator] Syntax highlighting partially broken by ...
Download and build the following solution: SyntaxHighlightingBug.zip. Restart Visual Studio to wire up the source generator (as is documented). Add an arbitrary ...
Read more >
Documentation - Creating Types from Types - TypeScript
An overview of the ways in which you can create more types from existing types. ... Indexed Access Types - Using Type['a'] syntax...
Read more >
How do you fix a broken type signature in a library for your ...
I'm using the debug and @types/debug packages in my project, and a recent update to @types/debug broke typings for code I know is...
Read more >
TypeScript with GraphQL done right - Charly Poly
Stronger generated TypeScript types; Getting the most of your ... The example below shows how easily this “types chain” can be broken:.
Read more >
Syntax Error - an overview | ScienceDirect Topics
Syntax errors are mistakes in the source code, such as spelling and punctuation errors, incorrect labels, and so on, which cause an error...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found