0

I have the following typescript in my test script:

const tmdBytes = Bytes.hex_encode("ipfs://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
const tmdMap : Array<[ string, Bytes ]> = [" ", tmdBytes]

The second line is giving me the errors:

Type 'string' is not assignable to type '[string, Bytes]'.
Type 'Bytes' is not assignable to type '[string, Bytes]'. 

I have tried to copy the example in the docs which is:

const ledger : Array<[ Address, Int ]> = []

The errors of course go away if I remove the values from the array, copying the docs exactly, but then I don't know how to add the values to the Map/Array.

My goal is to pass this array as a parameter in a test script, eg:

    await fa2_contract.mint(
      ownerAddress
      tmdMap,      
      {})

Any help appreciated, thanks.

2 Answers 2

1

I think you should try with this:

const tmdMap : Array<[ string, Bytes ]> = [[" ", tmdBytes]]

In typescript, tuple and array have the same literal []. And here, it is a tuple into an array.

1

The expected type reads "an array of pairs of string and bytes", and [" ", tmdBytes] is just a pair, hence I guess the following value should make ti:

const tmdMap : Array<[ string, Bytes ]> = [ [" ", tmdBytes] ]

As a side note, maps/assets are transpiled to arrays of pairs (asset) key and (asset) value, and the TS syntax for both arrays and tuples is [ ]. The reason for not transpiling to TS map objects is because the types of keys in TS maps does not deal easily with complex/composed keys.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.