You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Allow passing ReadonlyArray<T> and ReadonlySet<T> to expect.toBeOneOf #10264
Currently, the expect.toBeOneOf matcher does not allow passing in ReadonlyArrays or ReadonlySets in TypeScript without giving type errors.
The actual implementation does not modify either argument type in any way, shape or form - this is purely a typing issue.
Moreover, this would also prevent the asymmetric matcher from accidentally mutating its passed-in arguments (which could easily corrupt shared global state inside noIsolate runs).
Suggested solution
Change the typing to use ReadonlyArray<T> and ReadonlySet<T> instead of Array<T> and Set<T>.
Alternative
Don't pass in readonly arrays or sets (though this isn't exactly desireable)
changed the title [-]Allow passing `ReadonlyArray<T>`s to `expect.toBeOneOf`[/-][+]Allow passing `ReadonlyArray<T>` and `ReadonlySet<T>` to `expect.toBeOneOf`[/+]on May 4, 2026
I think it's fine to change, but there might be other places you want the same like:
import{it,expect}from'vitest';// imagine this is an external constant used elsewhereconstALLOWED=['A','B']asconst;it('should be A or B',()=>{expect('A').toBe(expect.toBeOneOf(ALLOWED));expect(['A']).toEqual(expect.arrayContaining(ALLOWED))});
Activity
[-]Allow passing `ReadonlyArray<T>`s to `expect.toBeOneOf`[/-][+]Allow passing `ReadonlyArray<T>` and `ReadonlySet<T>` to `expect.toBeOneOf`[/+]hi-ogawa commentedon May 5, 2026
I think it's fine to change, but there might be other places you want the same like:
https://www.typescriptlang.org/play/?ssl=10&ssc=1&pln=1&pc=1#code/JYWwDg9gTgLgBAbzsGAaOBTAHmDBjeAXzgDMoIQ4ByANxQwGcYqBuAWAChOB6b5EAIYBzYADsMcGAAtgDZHIGjMWGBiiiBAGzh4IopovgBXBhgAmmTaYDuUtRk6798AIIAZNwHkA6gFEAInAAvHAA2lQuVOhUAEJUALpwAnJOTOxcHCgAFFQMUhBGmhYARhIucNBwcehZAJTBAHyInHDKuAQ5kbUAdDAQMRhZ2O0wvf0YnuKeJFnuXn7+tbXprcP4MFnhkfE9fb4AjkZaQzjr3QJQUAIAngDCejACYmJCsx4+AUuchMucQA
Bertie690 commentedon May 6, 2026
Good catch.
this might warrant a sweep over all the asymmetric matchers to see which ones deserve this treatment.
hi-ogawa commentedon May 7, 2026
@Bertie690 Feel free to send a PR to test out the change.
fix(expect): allow readonly arrays and sets in toBeOneOf (fix #10264) (…
fix(expect): allow readonly arrays and sets in toBeOneOf (fix vitest-…