Closed stjepangolemac closed 7 years ago
so your syntax highlight is expecting toJSON(): string
and fromJSON(json:string)
?
Yes, the type definitions define those two functions as you wrote. For exporting to work I must do it like this:
let exported = JSON.stringify(myNetwork.toJSON());
let imported = Network.fromJSON(JSON.parse(exported));
Is this the expected way of exporting or not? Even without type definitions in your source file parameter is named json so one would assume it is a string type.
it is intended behavior. .toJSON
can return anything serializable, it should not return already serialized value, see docs: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#toJSON()_behavior
It makes sense now. Thanks.
Names of parameters in those two functions are misleading in a way that they should not be JSON strings but objects. Moreover, I am using a new version of Typescript with Visual Studio Code and it automatically resolves type definitions that define the same parameters as strings.
This is not a critical problem but it confused me and made me search for a solution for some time.