In the process of parsing a file, a large object is returned by the main function.
function parse(file){
/* dostuff.. */
return myObject
}
The order of determining properties is crucial (e.g., "a" must be determined before "b" or the value will be different). Here is a simple example:
type MyObject = {a:number, b:number, c:string} //long list of keys..
function parse():MyObject{
let myObject:{[key:string]:any} = { }
myObject.a = 'hello';
myObject.b = 5;
myObject.c = 55;
//...
return myObject as MyObject
}
However, myObject.a is expected to be a number but it is a string (similar issue with myObject.c). As a result, type checking becomes less effective.
How can this be improved? Perhaps by declaring each property as a const prop:type=value
initially?