Option represents a value that may be present or absent. In a Rust-backed key-value store, HashMap::get returns Option<String>: a stored value becomes Some, while a missing key becomes None. Keeping that possibility in the return type avoids pretending every lookup succeeds. section 3.4.2
For a WebAssembly component interface, express the same contract as option<string>. WIT supplies optional values as an interface-level type, and the Canonical ABI marshals richer interface values across host and guest boundaries rather than adding them as core Wasm primitives. section 2.4 section 3.4.2
A key-value lookup across the component boundary
Define get as returning option<string>, then return the HashMap lookup directly instead of calling unwrap. A JavaScript guest sees the generated declaration as string | undefined, where undefined corresponds to None. This makes the interface honest, but a guest that promises a string can still crash at runtime when a key is absent. section 3.4.2 section 3.4.3
Listing 3.8 The TypeScript declaration file for our key-value store interface
/** @module Interface component:smartcms/kvstore **/ export function get(key: string): string | undefined; export function set(key: string, value: string): void;
Inspect the generated TypeScript declaration to see option<string> represented as string | undefined for the JavaScript guest. section 3.4.3








