TypeChain icon indicating copy to clipboard operation
TypeChain copied to clipboard

Generate interfaces for structs alongside existing struct types

Open marcusnewton opened this issue 3 years ago • 4 comments

PR https://github.com/dethcrypto/TypeChain/pull/700 changed how struct types are generated. I've been importing these structs (before the properties were wrapped by PromiseOrValue<T>) to help me type check inputs in hardhat tests.

Perhaps alongside the existing struct types you could provide an interface type also:

export interface Foo {
  a: BigNumberish;
  b: BigNumberish;
};

export type FooStruct = {
  a: PromiseOrValue<BigNumberish>;
  b: PromiseOrValue<BigNumberish>;
};

export type FooStructOutput = [BigNumber, BigNumber] & {
  a: BigNumber;
  b: BigNumber;
};

marcusnewton avatar Aug 29 '22 07:08 marcusnewton

maybe generating PromiseOrValue<T> vs T should be done behind a flag? If PromiseOrValue<T> is possible in ethers it does not mean that it's good(like it is possible to write {} + [] in javascript but it does not mean that it's good code).

olehmisar avatar Oct 01 '22 15:10 olehmisar

PromiseOrValue seems to have caused inconvenience for a lot of people. I'd incline towards getting rid of it if we can't have it behind a flag.

zemse avatar Oct 01 '22 15:10 zemse

@zemse is getting rid of PromiseOrValue still the plan? I've been hoping for that to happen given how wide the impact is, but if not, I guess I better get to fixing those 127 type errors this change introduced 😓

freeatnet avatar May 15 '23 12:05 freeatnet

In v6 target, there's no PromiseOrValue. For v5 I've just opened up a PR.

zemse avatar May 15 '23 12:05 zemse