Pretty standard use case would be to create an empty object and fill it with the necessary data. At the end of the filling process, the object is going to contain all of its required properties, but when it gets created it has none and thus TypeScript wont allow me to type this new object with the correct type.
Example:
interface ISomeType {
x: string;
y: string;
}
function buildObj(): ISomeType {
const obj: ISomeType = {}; // TS Error: {} doesn't include x and y
obj.x = foo();
obj.y = bar(); // At the end of the filling process, the object is correct
return obj;
}
How do I deal with this issue? How do I make TypeScript understand that this new object is supposed to be of the specified type, it just doesn't have the required properties yet and will have them at the end?
If I mark obj with the type Partial<ISomeType> then I can't mark the function return type with ISomeType which is my intention.