dkjson: fix JsonState.exception type and make json types more accurate#81
Open
goldenstein64 wants to merge 6 commits intoteal-language:masterfrom
Open
dkjson: fix JsonState.exception type and make json types more accurate#81goldenstein64 wants to merge 6 commits intoteal-language:masterfrom
goldenstein64 wants to merge 6 commits intoteal-language:masterfrom
Conversation
hishamhm
reviewed
Mar 21, 2026
types/dkjson/dkjson.d.tl
Outdated
|
|
||
| local record dkjson | ||
| type InputJsonValue = string | number | boolean | ||
| | table | userdata -- can always be valid with getmetatable(value).__tojson defined |
Member
There was a problem hiding this comment.
This comment is about the userdata, right?
I wonder if it would work to encode this check like this
interface JsonUserdata is userdata
where getmetatable(self).__tojson
end
type InputJsonValue = string | number | boolean | table | JsonUserdata
this should allow things like
if v is dkjson.JsonUserdata then
s = dkjson.encode(v)
and
record MyUserdata is dkjson.JsonUserdata
-- ...
end
(On the phone, can't double check right now if there's any compiler gotchas)
Contributor
Author
There was a problem hiding this comment.
It's for both tables and userdatas. It looks like the JsonUserdata interface is valid with some tweaks, so I'll include it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
dkjson.JsonState.exceptionthe same type asdkjson.encodeexceptiondkjson.encodeanddkjson.JsonState.exceptionparameter types more accurateInputJsonValueto represent encodable valuesInputJsonUserdatato help guard encodable valuesdkjson.decodereturn type more accurateOutputJsonValueto represent possible decoded stringsNullfornullvalargument