proto-kit / framework

Apache License 2.0
27 stars 10 forks source link

`StateMap.from` Type Param Inference #140

Closed harrysolovay closed 2 months ago

harrysolovay commented 2 months ago

After discussion with @maht0rz, there is supposedly a limitation in o1js that breaks inference of type params for State.from/StateMap.from.

The following looks completely normal to Protokit beginners such as myself:

class NftId extends Field {}

// ...

@state() public nftMetadata = StateMap.from(NftId, Field);

Methods of the state map seem to produce the correct signatures.

this.nftMetadata.get(null!) // Option<Field>

Meanwhile, the documentation mentions the need for explicit type arguments.

- @state() public nftMetadata = StateMap.from(NftId, Field);
+ @state() public nftMetadata = StateMap.from<NftId, Field>(NftId, Field);

However, this seems to work without the explicit type args. Am I missing something? Has this limitation been overcome? If so, I'll put up a PR removing the note from the docs.

maht0rz commented 2 months ago

This issue seems to be already resolved thanks to the internal changes to o1js, we've also updated the docs in a separate PR: https://github.com/proto-kit/website/pull/12