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

Jsonify Map type returned as {} #457

Closed
MGibson1 opened this issue Sep 1, 2022 · 2 comments
Closed

Jsonify Map type returned as {} #457

MGibson1 opened this issue Sep 1, 2022 · 2 comments

Comments

@MGibson1
Copy link

MGibson1 commented Sep 1, 2022

I've been having an issue with parsing JSON serialized Map<TKey, TValue> in a type-safe way.

It comes down to the fact that Jsonify<Map<TKey, TValue>> return {} instead of taking the key/value types into consideration. I would expect Jsonify to treat Maps and Records equivalently

Expected result

type JsonifyMapType = Jsonify<Map<string, string>> // JsonifyMapType = {[key: string]: string}

Actual result

type JsonifyMapType = Jsonify<Map<string, string>> // JsonifyMapType = {}
@papb
Copy link
Contributor

papb commented Sep 2, 2022

I would expect Jsonify to treat Maps and Records equivalently

Why? JSON.stringify itself does not treat them equivalently:

const x = new Map([['a', 1], ['b', 2]]);
const y = { a: 1, b: 2 };
JSON.stringify(x); // '{}'
JSON.stringify(y); // '{"a":1,"b":2}'

To me, the current behavior is correct.

@MGibson1
Copy link
Author

MGibson1 commented Sep 3, 2022

Well, color me surprised. I should have tested that myself, you're 100% right.

@MGibson1 MGibson1 closed this as completed Sep 3, 2022
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