Conversation
Edited 5 months ago

y’all have no idea how much I would rather be able to write:

any(not isPrimitive(value) for value in someDict.values())

instead of:

Object.entries(someObject).some(([_key, value]) => !isPrimitive(value))
3
0
0

I’m trying to write a function that can pretty-print any type in javascript and it is Not Going Well. this language’s type system is actually horrifying. some object fields are hidden and can only be seen by certain functions and not others. null is an object, except typescript disagrees. JSON.stringify() silently ignores any field it doesn’t know how to deal with, and I can’t find any documentation for how it chooses which fields to discard, or any way to find out if it would discard a field if I were to use it

1
0
1

eli, vampire kitsune

Edited 5 months ago
unsolicited code/advce
Show content

@kasdeya this isnt gonna make it thaaaat much better but you could do

Object.values(someObject).some(value => !isPrimitive(value))

(especially since i think the python version of values is a lazy iterator that stops on first match and the javascript one isn’t)

1
0
1
re: unsolicited code/advce
Show content

@rowan that is a bit better - thank you! I forgot about Object.values()

1
0
1
re: unsolicited code/advce
Show content

@kasdeya if you use a Map instead of an object, you can also do

const someDict = new Map()
someDict.values().some(value => !isPrimitive(value))
1
0
1
re: unsolicited code/advce
Show content

@rowan unfortunately not - this is for pretty-printing any arbitrary object so it has to be an object T_T

0
0
1

“may your ancestors spend a hundred years trying to pretty-print things in TypeScript”

I give up lol this sucks. I was just trying to see what the window object in Bitburner has in it but nooo

0
0
1

@kasdeya

Fist, write your code. Then, write a compiler/interpreter for the code.

0
0
1