JavaScript Ergonomics
Open
@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.
- 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.
- 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 asresult.okorresult.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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.