You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was disappointed that LosslessNumber instance of Number is false, also I get weird type errors from lossless-json, I had to add an any (d is a string):
if I remove the as any, I get a type error from objToPython saying Argument of type 'unknown' is not assignable to parameter of type 'string | number | boolean | object | null'. ts(2345). Why does it think dataAsLosslessJson is unknown?
I'm a bit struggling with defining types for the library. For example the native JSON.parse is in my IDE giving the following TypeScript types:
So, there are two different levels of JSON, but what types can really come out of the function depend on the reviver and numberParser. Maybe with generics it is possible to define this strictly instead of relying on unknown (which covers LosselessNumber and anything).
Now, as for your specific questions and ideas:
The output of LosslessJSON.parse() is a JavaScriptValue. Your function objToPython(obj: string | number | boolean | object | null, indent = 0) does not accept the more broad definition of JavaScriptValue so it makes sense that TypeScript complains about that. I guess the logic solution is to make the first argument of objToPython compatible with JavaScriptValue. Or we have to be able to
It is an interesting idea to make LosslessNumber extend Number. I have to think that through a bit. It would make the wrapper class less lightweight: we would have to add all methods that Number has. But it can make usage more natural, and maybe we could make JSON.parse return JSONValue instead of JavaScriptValue somehow 🤔
The text was updated successfully, but these errors were encountered:
From #244:
I'm a bit struggling with defining types for the library. For example the native
JSON.parse
is in my IDE giving the following TypeScript types:Which is quite generic.
We can define JSON like:
lossless-json/src/types.ts
Lines 1 to 7 in 94d906c
But as soon as we have a
reviver
and/ornumberParser
, the output can be sort of anything. I tried to represent this as:lossless-json/src/types.ts
Lines 9 to 15 in 94d906c
So, there are two different levels of JSON, but what types can really come out of the function depend on the
reviver
andnumberParser
. Maybe with generics it is possible to define this strictly instead of relying onunknown
(which coversLosselessNumber
and anything).Now, as for your specific questions and ideas:
LosslessJSON.parse()
is aJavaScriptValue
. Your functionobjToPython(obj: string | number | boolean | object | null, indent = 0)
does not accept the more broad definition ofJavaScriptValue
so it makes sense that TypeScript complains about that. I guess the logic solution is to make the first argument ofobjToPython
compatible withJavaScriptValue
. Or we have to be able toLosslessNumber
extendNumber
. I have to think that through a bit. It would make the wrapper class less lightweight: we would have to add all methods thatNumber
has. But it can make usage more natural, and maybe we could makeJSON.parse
returnJSONValue
instead ofJavaScriptValue
somehow 🤔The text was updated successfully, but these errors were encountered: