dfinity / dfinity/candid

JavaScript Ergonomics

Open
#300 5 comments 0 reactions 1 assignee View on GitHub

@chenyan-dfinity is already working on this.

Since Dec 9, 2021.

enhancement
Dominant language
Rust
Stars
301
Forks
85
Avg merge
1h 4m
Merged PRs (30d)
4

Description

Currently, there are two issues with the JavaScript / TypeScript bindings that make development inconvenient for IC developers.

  1. Options
  • Optional nested values in JavaScript are denoted idiomatically using the Optional Chaining operator (?.)
  • Our generated pattern, of a null value being represented as [] does not align with expectations of developers, as Arrays are used to represent ordered data.
  1. Variants
  • For Variants such as Result.Result, we get back a typing that is not ideal for JavaScript, and requires developers to add a significant amount of boilerplate and error handling.
  • a type of { ok : () } | { err: string } cannot be safely accessed as result.ok or result.err, but requires the user to write something like
if ('ok' in result){
 // continue
}
else if ('err' in result) {
 // handle result.err
}
* This code is unsafe, and is problematic for TypeScript in particular. Instanceof is also not reliable for determining which case is represented.

Describe the solution you'd like

  • Replace options with Optional Chaining
    • may require additional support in the JS Agent for converting null back to the candid type
  • Handle variants with a "kind" attribute that will always be present and checkable in variants

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.