I would like to create a type that specifically extracts the mutable object type from an existing immutable object type like such:
import * as Immutable from 'seamless-immutable'
interface IObjType {
field: string;
}
type TObjImmType = Immutable.Immutable<IObjType>;
const obj: IObjType = { field: 'val' };
const objImm: TObjImmType = Immutable(obj);
// dummy function to demonstrate what I am trying to achieve
const getMutable = (immObj: TObjImmType): IObjType => immObj.asMutable();
const result = getMutable(objImm);
The issue lies within the getMutable
function. TypeScript does not check if it returns a mutable or immutable object, and I need to enforce TS to verify this and throw an error if an immutable object is returned.
How can this be accomplished?