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

Allow users to provide type hints to Value.from() #620

Open
zslayton opened this issue Jun 25, 2020 · 1 comment
Open

Allow users to provide type hints to Value.from() #620

zslayton opened this issue Jun 25, 2020 · 1 comment

Comments

@zslayton
Copy link
Contributor

zslayton commented Jun 25, 2020

Currently, Value.from converts all JS arrays into ion.dom.Lists and all Uint8Arrays into ion.dom.Blobs. Users hoping to create ion.dom.SExpression or ion.dom.Clob have to instantiate them manually, which is much more tedious.

We should modify Value.from to accept an optional expected type hint. This is trivial for handling the top level value:

let jsValue = [1, 2, 3];
let annotations = ["foo", "bar"];
let list = Value.from(jsValue, annotations);
// foo::bar::[1, 2, 3]

let expectedType = IonTypes.SEXP;
let sexp = Value.from(jsValue, annotations, expectedType);
// foo::bar::(1 2 3)

However, it's unclear how to specify the expected outcome of converting nested JS values. Would the expectedType hint apply to ALL Arrays and Uint8Arrays encountered during conversion? Is there a better API?

@donpdonp
Copy link

Similarly I was hoping to be able to say ion.dom.Value.from(IonTypes.Date, "2021-01-1") and have the library convert the date string into an Ion date value.

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

No branches or pull requests

2 participants