My goal is to select a TS interface or type based on an external condition rather than the input.
This external condition could be a feature toggle, for example.
Allow me to elaborate:
type NotEmptyName = string;
type EmptyableName = string | null;
const getNotEmptyName = (name: NotEmptyName) => name
const getEmptyableName = (name: EmptyableName) => name
Currently, I am doing:
const getName = externalCondition ? getNotEmptyName : getEmptyableName;
However, I would like to achieve something like this:
const getName = (name: externalCondition ? NotEmptyName : EmptyableName) => name
Is there a way I can make this happen?