When I attempt the following code snippet:
import { MyType } from 'somewhere';
class MyClass {
myObj: MyType = new MyType();
updateObject(newVal: string): void {
myObj.thing = newVal;
this.saveStuff(JSON.stringify(myObj));
}
saveStuff(json: JSON): void {
// http request...
}
}
I encounter an error indicating that I am passing a string instead of JSON, despite being aware that it is actually a string. How can I adjust it to treat the string as JSON?
I experimented with attempting to cast the string as JSON like so: JSON.stringify(foo) as JSON
or <JSON> JSON.stringify(foo)
. However, in both cases, I receive an error stating "Type 'string' cannot be converted to type 'JSON'."