playwright
playwright copied to clipboard
[Feature]: export MakeMatchers type (& related types)
🚀 Feature Request
I want to be able to re-use the MakeMatchers type and related types in wrapper APIs for playwright.
While it's possible to infer the type of MakeMatchers with ReturnType<typeof ...>, the resulting type isn't named and becomes a problem when generating declarations for a lib that is to be distributed.
In my local instance of playwright I've used pnpm patch to expose these types. I thought I would push the same patch as a PR to playwright, so that others could also create similar wrapper functions.
https://github.com/microsoft/playwright/pull/32139
Example
In our use case we are writing a 'batch' expect, allowing us to run the same assertion on multiple targets. Exposing MakeMatchers allows us to create an API like this:
this.$expect('one', 'two', 'three').toBeAttached()
Instead of:
this.$expect(`one`, `two`, `three`, (x) => x.toBeAttached())
It's not a huge difference, but sometimes it feels good to be able to have nice things...
Motivation
Being able to directly re-use these types will open up more possibilities for library authors to extend playwright's expect API in more interesting and useful ways.
While it's possible to infer the type of MakeMatchers with ReturnType<typeof ...>, the resulting type isn't named and becomes a problem when generating declarations for a lib that is to be distributed.
Can you give an example of such problematic declarations? Why can't you use type alias, something like type MyType = ReturnType<typeof ....>; if you need a nice type names in the lib that would be based on Playwright's?
We need more information to act on this report. As long as we can't repro it, it is unlikely with can make progress with it. Allow me to close it, but please file a new one and link to this issue when you get back to it!