I have a function with an overload:
interface FunctionWithOverload {
(): {
a: 1
b: 1
}
<T>(arg: T): {
a: 1
b: 1
} & (T extends number ? { c: 1 } : {})
}
const fwo: FunctionWithOverload = () => {return {} as any}
const result = fwo() // result has a nice type: {a: 1, b: 1}
const result1 = fwo(1) // result1 does not: {a: 1, b: 1} & {c: 1}
If you hover over result
, you can see it has a nice type {a:1,b:1}
in the tooltip, however result1
has an ugly type {a:1, b:1} & {c:1}
.
The question is: how do I somehow merge {a:1, b:1} & {c:1}
to {a:1, b:1, c:1}
in my case?
Requirements
The function overloads must be as they are, i.e. I am not allowed to add a mutual optional property c
to the return type.
Any type alias names shouldn't be added to the output in the tooltip (unless it's the only solution to this problem).
The prettiness matters because it's in the requirements of my task.