export type Name = { name: string }
export type Id = { id: number }
export type Value = T extends string ? Name : Id
export function create
I'm not sure I understand your example fully, but I think this is what you want?
type Name = { name: string }
type Id = { id: number }
type Value = Name | Id
export function create(value: string | number): Value {
if (typeof value === "string") return { name: value }
return { id: value }
}
See, that I've removed any generics from your example, since I don't see the need for them in this case