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

Returning an unboxed string value from an external function can fail. #27

Closed
mwchase opened this issue Sep 20, 2016 · 2 comments
Closed

Comments

@mwchase
Copy link

mwchase commented Sep 20, 2016

I hit this in the same experimentation that led to #26. Casting from strings to StringValues is extremely finicky, in ways I don't quite understand. It appears that round-tripping a string from Ink to js to Ink works, and the string looks like a normal string in the console. But if I return a string defined in JavaScript from an external function, then it will fail unless I use new String("foo"), apparently because "foo" instanceof String is false.
I don't know JavaScript well enough to understand how this behavior is even possible, but it happens.

@erkyrath
Copy link

Javascript is terrible. It is known.

You can use the test (typeof(val) == 'string' || val instanceof String) , I'm pretty sure.

@y-lohse
Copy link
Owner

y-lohse commented Sep 20, 2016

> 'a' instanceof String
false
> typeof 'a'
"string"

....right. Surely there's a npm module for that!
Just kidding, but yes, the String detection tests ned revision. Thanks for pointing it out! Feel free to submit a PR, otherwise I'll have a look at it when I get the chance.

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

3 participants