bind, call and apply do not work on unions of function types with different return types. #33815
Labels
Awaiting More Feedback
This means we'd like to hear from more people who would be helped by this feature
Suggestion
An idea for TypeScript
TypeScript Version: 3.6.3
Search Terms:
call, bind, apply, function, functions, Function.prototype.call, Function.prototype.apply, Function.prototype.bind, union, return, this, strictBindCallApply
Code
Expected behavior:
Code compiles. The types in this code are equivalent to the types in the following example, which does compile:
The only difference between the two examples is that the first uses a type union of function types
aFn
andbFn
, which only differ in terms of return value, whereas the second uses a type union in the return value ofcFn
. In other words I think the union of typeaFn
andbFn
should behave the same as typecFn
.Actual behavior:
Playground Link:
https://www.typescriptlang.org/play/index.html?ssl=30&ssc=2&pln=1&pc=1#code/PTAEBcAsFMGdtNAHgQwLYAcA2dQBMB7UAOwPFAHcCAnAawChwBPDBFAMWNAF5QAKKAEtYALlCxw1QcQDmAGlAA3FFgCu0MRKmyAlDwB84ydJkBuRiwQAjTj35DRR7fKUr1m47oOgACtQJowtAAPFom+ub0AGaqxADG4IIEXHEqWJx8qVhYVihxtGIcXAA+oDbEOmJ+AUGhnjKGpWGyoADe9KCdoNTQ4KrUKWm5+QB0WVh8AEQw2QSTCpNU1Fh4kzrmAL700bEJSVwoGNhMGePDBaBFoKXllb7+gfB1zo1OJm0dXT19A6BnebQRodjlMZlg5goANqLGgrSYAXXW9C2O3iiWSZWkeFOQwBhVsN04dz4em4hmqjxCzQa1zeLXaXW6vX6g2y5xGVixoOgs3moBhy1WSJRIAgMHgiFQmBw+CISwYzFYf1svAEkGEHmcCmUag0dJkpMM1NpFNq1Ii2xiaP2fzSnAAjJlcfkxHEiVUHmb6q9jQyvszfv9RuNubyFks4cLLbt0QcjlgTsRHUGLm6Kh6ak9zbTfZ9Ot8Wba2QCgfGmKHwXzoRHVojNtHrRjOcRsUmncWXcr0-xDfdM1TvTn6h9GQXA87Ac28BWIfya2tNkA
Related Issues:
The text was updated successfully, but these errors were encountered: