FuelLabs / fuels-ts

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

Improve DX for `IdentityInput` #1891

Open arboleya opened 8 months ago

arboleya commented 8 months ago

Discussed in https://github.com/FuelLabs/fuels-ts/discussions/1844

Originally posted by **Dhaiwat10** March 7, 2024 Take this Sway function signature for example: ```sw fn new_game(player: Identity); ``` If you try to call this function via the TS SDK, it would look something like this: ```ts await contract.functions.new_game({ Address: { value: walletAddress }); await contract.functions.new_game({ ContractId: { value: contractId }); ``` The idea is to change it to something like: ```ts type Identity = {address: string, contractId?: never} | {address?: never; contractId: string} await contract.functions.new_game({ address: walletAddress }); await contract.functions.new_game({ contractId: contractId }); ```
nedsalk commented 7 months ago

It seems to me that we can generalize this approach for all enums, not just the Identity one? For example, this is currently possible:

// call-test-contract
    const { value } = await contract.functions
      .take_b256_enum({ Value: 'qweqwe', Data: 'asds' })
      .call();

But we'd want to only provide Value or Data.