export type Name = { name: string }
export type Id = { id: number }
export type Value = T extends string ? Name : Id
export function create
The problem is inside the function T is not known, so you can't really assign a value to Value. One option would be to use a type assertion. A more type safe option would be to use a separate implementation signature, that would be more relaxed about the input and output type:
export function create(value: T): Value // public signature
export function create(value: string | number): Name | Id { // more relaxed private implementation signature
if (typeof value === "string") return { name: value }
return { id: value }
}