When building out Scripts and Predicates using configurables, I encountered some issues with the generated types (which can be found below with examples). The following PR has the expanded example that should showcase the issue.
As part of this, we should:
Add valid typegen output for Option, Enum and Struct
Expand the example from the PR, adding all types used to the inputs of the script and predicate.
Add tests around these two script and predicate, ensuring that we can use the typegen'd resuts, pass inputs and update configurables.
```sway
enum GenericEnum {
Foo: u64,
}
configurable {
configurableEnumWithGeneric: GenericEnum = GenericEnum::Foo(0),
}
```
#### Actual
```ts
// V generic is unused
export type GenericEnumInput = Enum<{ Foo: BigNumberish }>;
export type GenericEnumOutput = Enum<{ Foo: BN }>;
export type AbiConfigurables = Partial<{
// We don't pass in any generic type to `GenericEnumInput` so TS complains
configurableEnumWithGeneric: GenericEnumInput;
}>
```
#### Expected
```ts
// V should extend the given type and default to the that type
export type GenericEnumInput = Enum<{ Foo: V }>;
export type GenericEnumOutput = Enum<{ Foo: V }>;
export type AbiConfigurables = Partial<{
configurableEnumWithGeneric: GenericEnumInput;
}>
```
Option
```sway
struct GenericStruct {
Boo: T
}
configurable {
configurableStructWithGeneric: GenericStruct = GenericStruct {
Boo: 0
},
}
```
#### Actual
```ts
// T is used, however, we don't enforce a type
export type GenericStructInput = { Boo: T };
export type GenericStructOutput = GenericStructInput;
export type AbiConfigurables = Partial<{
// We don't pass in any generic type to `GenericStructInput` so TS complains
configurableStructWithGeneric: GenericStructInput;
}>
```
#### Expected
```ts
// T should extend the given type and default to the that type
export type GenericStructInput = { Boo: T };
export type GenericStructOutput = GenericStructInput;
export type AbiConfigurables = Partial<{
configurableStructWithGeneric: GenericStructInput;
}>
```
Summary
When building out
Scripts
andPredicates
using configurables, I encountered some issues with the generated types (which can be found below with examples). The following PR has the expanded example that should showcase the issue.As part of this, we should:
Option
,Enum
andStruct
script
andpredicate
.script
andpredicate
, ensuring that we can use the typegen'd resuts, pass inputs and update configurables.Details
```sway configurable { configurableOption: OptionOption
```sway enum GenericEnumEnum
```sway struct GenericStructOption