assemblyscript-json icon indicating copy to clipboard operation
assemblyscript-json copied to clipboard

Adjust types for the encoder to allow null strings

Open zwade opened this issue 6 years ago • 3 comments

Summary

In order to create top level arrays, or objects, or to place an element in an array, one needs to pass in null for the key. However, with the typing definitions for assemblyscript-json, and the default tsconfig for assemblyscript proper, null is not a valid argument to these functions

Current Solution

For right now, you can use changetype<string>(0) to get around this.

Suggested Solution

It would be nice to have all of the name types to be alternated with null.

zwade avatar Apr 07 '19 00:04 zwade

I'll try to make a PR later, but I'm pretty busy right now.

zwade avatar Apr 07 '19 00:04 zwade

It would be nice to have all of the name types to be alternated with null.

Hmm, is this already supported by AssemblyScript? Do you have any example?

vgrichina avatar Apr 07 '19 04:04 vgrichina

I think all non-primitive types in AssemblyScript can be alternated with null. Since strings are basically just uint16le arrays, they count as non-primitive.

(Just to double check, I compiled and ran this function

export function f(input: string | null): void {
	if (input === null) {
		console.logS("nope, it's null");
	} else {
		console.logS(input);
	}
}

It worked as expected.)

zwade avatar Apr 07 '19 13:04 zwade