Closed JacobOaks closed 4 months ago
All modified and coverable lines are covered by tests :white_check_mark:
Project coverage is 98.46%. Comparing base (
cb9cccf
) to head (afe49a5
).
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
Changes look great and pretty isolated. Added a couple of comments.
Addressed!
We frequently see requests for folks who want to use
fx.As
to provide a type as another type, while also providing it as itself. To name a few:This is currently not possible via strictly using
fx.As
+ a single constructor, sincefx.As
causes a constructor to no longer provide its original type. The workaround we often give is for folks to do something like this, which involves adding a second "constructor":which is admittedly not very ergonomic. A somewhat common pattern mistaken to be a workaround is providing the constructor twice instead:
This PR adds
fx.Self()
, which returns a special value to indicate anfx.As
should retain that original return type:As an alternative, I considered a new annotation altogether, named something like
fx.AlsoAs
, but adding a special type that can be passed as an argument tofx.As
directly allows for more fine-tuned control over individual positional return values.For example, this function's return types can be easily expressed as
*asStringer
andio.Writer
usingfx.Self()
:Whereas something like
fx.AlsoAs
wouldn't provide the ability to skip over the first positional return value entirely.