feat(test runner): improve fixture typings for function fixtures#9138
Merged
Conversation
When fixture value `R` is a function, TypeScript sometimes confuses
function `R` and function `async ({}, use) => {}`. This leads to
`any` types in the latter because it could be either of the functions
as TS thinks.
The solution is to only accept the second syntax, assuming that noone
passes fixture value that is a function as is:
```js
// This will stop working.
test.extend<{ foo: (x: number) => number }>({
foo: x => 2 * x,
});
// This will get inferred types and autocomplete.
test.extend<{ foo: (x: number) => number }>({
foo: async ({}, use) => {
await use(x => 2 * x);
},
});
```
JoelEinbinder
approved these changes
Sep 25, 2021
sidharthv96
added a commit
to sidharthv96/playwright
that referenced
this pull request
Sep 28, 2021
* upstream/master: (26 commits) browser(webkit): disable COOP support (microsoft#9185) fix(test runner): proper serial mode with beforeAll/afterAll failures (microsoft#9183) chore: remove browserType.connect from .net - not yet ready (microsoft#9182) test: canvas updates are reflected on screenshots (microsoft#9180) chore: dedupe return types in the dotnet api generator (microsoft#9181) docs: mention empty string in `userDataDir` (microsoft#9069) feat(expect): toContainText(array) (microsoft#9160) chore: enable object-curly-spacing in ESLint (microsoft#9168) feat(chromium): roll to r925110 (microsoft#9175) chore: render expect in trace viewer (microsoft#9141) devops: use Node.js 16 when rolling browsers docs(python): add docs about threading (microsoft#8829) browser(chromium): roll to r925110 (microsoft#9171) chore(test-runner): launch -> webServer (microsoft#9167) docs: cleanup test.describe.parallel.only doc (microsoft#9159) chore: remove FatalDOMError (microsoft#9119) feat(test runner): improve fixture typings for function fixtures (microsoft#9138) fix(expect): produce "waiting for selector" log, corner cases (microsoft#9140) fix: increase recent logs buffer (microsoft#9143) test: unflake a few tests (microsoft#9142) ...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When fixture value
Ris a function, TypeScript sometimes confuses functionRand functionasync ({}, use) => {}. This leads toanytypes in the latter because it could be either of the functions as TS thinks.The solution is to only accept the second syntax, assuming that noone passes fixture value that is a function as is:
Fixes #9116.