Problem Description
Currently, when sharing selectors/locators between adjacent steps (e.g. from .detect() to .prep()), the downstream step receives a loosely-typed lastOutcome object. Developers must manually cast the locator (e.g., lastOutcome.locator as Locator) and do not get autocomplete or type-safety on the outcome names:
.detect((page) => [
{ name: 'found', isSuccess: true, locator: page.getByRole('textbox', { name: 'Name' }) }
])
.prep('fill details', async (page, ctx, lastOutcome) => {
if (lastOutcome?.name === 'found') { // No autocomplete or type safety
const input = lastOutcome.locator as Locator; // Manual typecast required
await input.fill('value');
}
})
Proposed Solution
Refactor the generic types of the Play builder class so that the list of outcomes defined in .detect() or .attempt() maps to a strongly-typed union. Downstream steps should automatically infer:
lastOutcome.name (restricted to the literal string names defined in the prior step).
lastOutcome.locator (typed properly as Locator instead of any or unknown).
Problem Description
Currently, when sharing selectors/locators between adjacent steps (e.g. from
.detect()to.prep()), the downstream step receives a loosely-typedlastOutcomeobject. Developers must manually cast the locator (e.g.,lastOutcome.locator as Locator) and do not get autocomplete or type-safety on the outcome names:Proposed Solution
Refactor the generic types of the
Playbuilder class so that the list of outcomes defined in.detect()or.attempt()maps to a strongly-typed union. Downstream steps should automatically infer:lastOutcome.name(restricted to the literal string names defined in the prior step).lastOutcome.locator(typed properly asLocatorinstead ofanyorunknown).