You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@jack-williams hard to find related items when I confuse union for intersection!
JasonKleban
changed the title
Redundant union type from overloaded function signature
Redundant intersection type from overloaded function signature
Mar 28, 2018
TypeScript Version: 2.8.1
Search Terms:
redundant intersection conditional type function overload
Code
Expected behavior:
Inferred type should be reduced:
// const x: (parameters: { a: string; b: string; }, option: string | string[]) => void
Actual behavior:
Inferred type is a redundant union:
// const x: (parameters: { a: string; b: string; } & { a: string; b: string; }, option: string | string[]) => void
It works as expected if
parameters
isstring
instead of the composite type{ a, b }
Playground Link:
https://www.typescriptlang.org/play/#src=%0D%0Ainterface%20ExampleFn%20%7B%0D%0A%20%20%20%20(parameters%3A%20%7B%20a%3A%20string%2C%20b%3A%20string%20%7D%2C%20option%3A%20string%5B%5D)%20%3A%20void%0D%0A%20%20%20%20(parameters%3A%20%7B%20a%3A%20string%2C%20b%3A%20string%20%7D%2C%20option%3A%20string)%20%3A%20void%0D%0A%7D%0D%0A%0D%0Atype%20Implementation%3CP%3E%20%3D%20%7B%0D%0A%20%20%20%20(parameters%3A%20P%2C%20option%3A%20string%5B%5D)%20%3A%20void%0D%0A%20%20%20%20(parameters%3A%20P%2C%20option%3A%20string)%20%3A%20void%0D%0A%7D%0D%0A%0D%0Atype%20Factory%3CX%3E%20%3D%20%0D%0A%20%20%20%20X%20extends%20Implementation%3Cinfer%20P%3E%0D%0A%20%20%20%20%3F%20(parameters%3A%20P%2C%20option%3A%20string%20%7C%20string%5B%5D)%20%3D%3E%20void%0D%0A%20%20%20%20%3A%20never%0D%0A%0D%0Adeclare%20const%20x%20%3A%20Factory%3CExampleFn%3E%3B%0D%0A%0D%0A%0D%0Ax%20%20%2F%2F%20const%20x%3A%20(parameters%3A%20%7B%20a%3A%20string%3B%20b%3A%20string%3B%20%7D%20%26%20%7B%20a%3A%20string%3B%20b%3A%20string%3B%20%7D%2C%20option%3A%20string%20%7C%20string%5B%5D)%20%3D%3E%20void
Related Issues:
none found
The text was updated successfully, but these errors were encountered: