nearprotocol / assemblyscript

A TypeScript to WebAssembly compiler 🚀
https://assemblyscript.org
Apache License 2.0
8 stars 1 forks source link

The following contract does not compile: #53

Closed janedegtiareva closed 5 years ago

janedegtiareva commented 5 years ago

//@nearfile import { near, context, storage, logging, base58, base64, PersistentMap, PersistentVector, PersistentDeque, PersistentTopN, ContractPromise, math } from "near-runtime-ts"; import { u128 } from "bignum";

export function setKeyValue(key: string, value: string): void { storage.set(key, value); }

export function getValueByKey(key: string): string { return storage.get(key); }

export function setValue(value: string): string { storage.set("name", value); return value; }

export function getValue(): string | null { return storage.get("name"); }

bowenwang1996 commented 5 years ago

It would be good to know what the error message is.

janedegtiareva commented 5 years ago

ERROR TS2531: Object is possibly 'null'.

return storage.get(key);

 in assembly/main.ts(938,9)

ERROR TS2531: Object is possibly 'null'.

     encoder.setString(name, value);

in ~lib/nearEntry.ts(53,28)

Note that adding ! still results in a compile error: ERROR TS2531: Object is possibly 'null'.

 encoder.setString(name, value);
                         ~~~~~

in ~lib/nearEntry.ts(53,28)

janedegtiareva commented 5 years ago

fixed! Thank you!