FuelLabs / fuels-ts

Fuel Network Typescript SDK
https://docs.fuel.network/docs/fuels-ts/
Apache License 2.0
44.22k stars 1.34k forks source link

Typegen generating invalid types with Scripts and Predicates #2832

Closed petertonysmith94 closed 2 months ago

petertonysmith94 commented 2 months ago

Summary

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:

Details

Option

```sway configurable { configurableOption: Option = Some(0), } ``` #### Actual ```ts export type AbiConfigurables = Partial<{ configurableOption: Option; }> ``` #### Expected ```ts export type AbiConfigurables = Partial<{ configurableOption: Option; }> ```

Enum

```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; }> ```
nedsalk commented 2 months ago

Fixed in commit https://github.com/FuelLabs/fuels-ts/pull/2826/commits/90e770aa41cb314e4fd78bb10437f96e4abc68aa of #2826.