icp-cli: bindgen record fields with opt are undefined when empty, not null
メンテナーはふだん 6 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 78/100
- issue の種類
- ドキュメント
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- typescript
- 領域
- documentation, testing
調査の方向性
skills/icp-cli/references/binding-generation.md:67-69 と、「Candid opt T representation in bindgen」という名前の既存のevalを読んでください。単純なopt値とoptionalなrecordフィールドを区別し、バージョンに依存しない空値チェックを推奨し、recordフィールドのケース用のevalを追加するよう、ドキュメントを更新してください。修正されたマッピングが文書化され、新しいevalが合格すれば完了です。
索引モデルが issue の本文から書いたものです。
説明
skills/icp-cli/references/binding-generation.md:67-69 says bindgen's wrapper turns opt T into T | null and tells agents to "always use T | null". That holds for a plain opt, but not for a record field: an opt T field is an optional property that is undefined when empty. An agent following the rule writes if (r.value !== null), which is true for an empty field. The certified-variables helper had exactly this bug: it rejected a valid proof of absence (fixed in #407).
Verified against the @icp-sdk/bindgen 0.4.0 and 0.4.1 wrappers:
| Candid position | Wrapper type | Empty value |
|---|---|---|
argument, return value, vec element, variant payload: opt T |
T | null |
null |
record field f : opt T |
f?: T |
undefined (field omitted) |
nested opt opt T (not in a record) |
Some<T | null> | None |
None |
Needed regardless of the bindgen PRs
These hold on 0.4.1 and after dfinity/icp-js-bindgen#197, dfinity/icp-js-bindgen#198 and dfinity/icp-js-bindgen#201:
- Correct the section in
binding-generation.md.T | nullapplies to a plainopt. A record field is optional andundefinedwhen empty. To send an absent field, omit it or passundefined. - Recommend
== nullor??for "is it empty". It is correct in every position and version, so an agent doesn't need to know which position it is in. - Add an eval for the record-field case. The existing case ("Candid opt T representation in bindgen") covers only a plain return value, and its expected
result !== nullstays correct. - Fix it in place, in
icp-cli. #406 movesbinding-generation.md'soptsection intocanister-callslater; the move then carries the corrected text. #406's own Candid↔TS table had the same gap (opt T→T | nullonly) and is corrected there, since it is the long-term home of the full mapping.
After the bindgen fixes are released
-
dfinity/icp-js-bindgen#197 (present but falsy optionals): until it ships,
0,falseand""in an optional record field or variant payload are sent as absent. No skill change is needed once it ships. If it is skipped, add a pitfall: send such values only in a plainoptargument, or avoid falsy values in optional fields. -
dfinity/icp-js-bindgen#198 (
opt optrecord fields): once released, documentf?: T | nullwith its three states (omitted,nullforopt null, a value), pinned to that bindgen version. If it is skipped, the skill must say instead thatopt optrecord fields do not match their declared type (they decode toSome/Noneobjects, andnullcannot be sent), and point to the raw declarations for those fields. -
dfinity/icp-js-bindgen#201 (actor class name): once released, generating the actor files for a
.didfile named after one of its own types (governance.didwithtype Governance,swap.didwithtype Swap) fails with a hint to rename the file. Where the skill shows vendoring NNS or SNS interfaces, if anywhere, use a distinct file name (e.g.nns_governance.did). The same advice applies if it is skipped, since the class then merges with the type without an error. -
dfinity/icp-js-bindgen#203 (docs for
--actor-interface-file): no skill change. It documents the.d.tsas a reference that leaves out the actor class, which is howcaffeine-app(--actor-interface-file) andwriting-motoko("use the generatedbackend.d.tsas the source of truth") already use it; neither imports it. -
dfinity/icp-js-bindgen#172 (proposed, no PR yet): if adopted, an inline unit variant becomes a string-literal union instead of a
Variant_<tags>or borrowed enum. No skill referencesVariant_<tags>today, so nothing breaks; the mapping in #406 then gains that row.
Until the bindgen PRs are decided, document only the first section.
- 主要言語
- Python
- スター
- 39
- フォーク
- 19
- 平均マージ
- 5日 3時間
- マージ済み PR(30日)
- 19
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
dfinity/icskills のほかの issue
-
generated hallucination skill-improvement
難易度 2/5 1〜3時間 初心者へのやさしさ 90/100
メンテナーはふだん 6 日以内に返信
-
Version drift: mo:core pinned at 2.0.0 / 2.3.1 / 2.5.0 across skills対応中かも @raymondk が 95 日前に担当しました。 オープンgenerated
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 6 日以内に返信
-
generated
難易度 1/5 1〜3時間 初心者へのやさしさ 78/100
dfinity/icskills#292 · コメント 1 件 ·
メンテナーはふだん 6 日以内に返信
-
generated
難易度 1/5 1〜3時間 初心者へのやさしさ 72/100
dfinity/icskills#291 · コメント 1 件 ·
メンテナーはふだん 6 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
メンテナーはふだん 6 日以内に返信
dfinity/icskills の issue をすべて見る
似ている issue
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 2 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
cunla/fakeredis-py#636 ·
メンテナーはふだん 2 日以内に返信
-
namespace
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
EclipseFdn/open-vsx.org#15470 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
opensafely-core/job-server#6180 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
area:models enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信