dfahlander / typeson-registry

The type registry for typeson
MIT License
6 stars 5 forks source link

Bug with shared reference + ES Set #27

Open Jack-Works opened 2 years ago

Jack-Works commented 2 years ago

Code:

import { Typeson } from 'typeson'
import { builtin } from 'typeson-registry'
const typeson = new Typeson().register([builtin])

const shared_reference = { hi: 1 }
const original = [
    //
    new Set([shared_reference]),
    new Set([shared_reference]),
]
console.log('Original:', original)

const toJson = typeson.encapsulate(original)
console.log('toJson:', toJson)

console.log('Revived:', typeson.revive(toJson))

image

brettz9 commented 2 years ago

While our Set type may be inadequate to handle such references, I wonder if typeson proper may also have issues dealing with this.

Unfortunately, I don't have the time to dig into this now. The typeson codebase and relevant portions of typeson-registry are not large, however, so you might be able to figure out an approach. Sorry couldn't be of more help.

Jack-Works commented 2 years ago

Thanks for your reply! I understand that. I turn off the cyclic reference feature to make it work again.