Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust types for the encoder to allow null strings #5

Open
zwade opened this issue Apr 7, 2019 · 3 comments
Open

Adjust types for the encoder to allow null strings #5

zwade opened this issue Apr 7, 2019 · 3 comments

Comments

@zwade
Copy link

zwade commented Apr 7, 2019

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
Copy link
Author

zwade commented Apr 7, 2019

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

@vgrichina
Copy link
Collaborator

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?

@zwade
Copy link
Author

zwade commented Apr 7, 2019

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.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants