I want a function to return either an object or null.
Here is how I handle it today:
export interface MyObject {
id: string
}
function test(id) : MyObject | null {
if (!id) {
return null;
}
return {
id: id
}
}
Is this best practice?
I would prefer to make the interface nullable rather than returning MyObject | null.
But I don't know if that is possible.