Skip to content

feat: type inference#6

Merged
hanakannzashi merged 22 commits into
mainfrom
feat/type-inference
Mar 30, 2025
Merged

feat: type inference#6
hanakannzashi merged 22 commits into
mainfrom
feat/type-inference

Conversation

@hanakannzashi

@hanakannzashi hanakannzashi commented Feb 12, 2025

Copy link
Copy Markdown
Member

Implement type inference, this is a simple minimal implementation, use 1:1 mapping of JS type, still remain many features to be added.

  • Support Uint8Array and other typed arrays

  • Support literal enums

    enum Status { 
      Pending = 'Pending',
      Fulfilled = 'Fulfilled',
      Rejected = 'Rejected',
    }

    There is a challenge that how to represent Rust enum with JavaScript

  • Support tuple

@hanakannzashi

Copy link
Copy Markdown
Member Author

Will be helpful if you guys have a look @r-near @hmtrent

@hanakannzashi

Copy link
Copy Markdown
Member Author

Another question is should we distinguish between schemas that have same generic type. e.g. u8 and u16 are both BorshSchema<number>, should change to BorshSchema<number, 'u8'> and BorshSchema<number, 'u16'>?

@hmtrent

hmtrent commented Feb 15, 2025

Copy link
Copy Markdown

I think #4 is probably on a closer track towards implementing type inference, which also currently is 1:1 with input/output type mappings. I agree that this is desirable.

Note that #4 has the TypeOf helper, which does what Infer is trying to do in this PR. In order for Infer to work properly, it will more or less need to look like the TypeOf type helper in that PR.

I'd recommend sticking with PR #4 instead of this one; are there any new features we should port over to that PR?

@r-near

r-near commented Feb 23, 2025

Copy link
Copy Markdown

@hanakannzashi looks good - feel free to take a look at the implementation here - it's before I went crazy and rewrote the library. But this would essentially be the most minimal changes required to make sure everything's fully-typed and backwards-compatible (comments are excluded):

@hanakannzashi hanakannzashi merged commit bd112b8 into main Mar 30, 2025
@hanakannzashi hanakannzashi deleted the feat/type-inference branch March 30, 2025 08:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants