Its not the first time that i found myself in the situation where im building up an object and then wanting to return the Object, something like the following:
function createUser(options) {
const returnObject: Partial<User> = {}
// assigning some dynamic values with different conditions based on options
return returnObject as User;
}
As you might notice, i use Partial<User> because the object does not yet have the required values, hence preventing me from getting the ts error XXX is missing the following properties from type ...
When returning the Object i now have to use as User once it is complete. The problem with this is that it will not throw any TypeScript errors even when properties would have been forgotten.
Are there ways to do this while still letting typescript make sure that all the values are on the returned object?