Clear and concise description of the problem
Here are some things you cannot write in mixed constraint position that you might want to do for one reason or another:
extern dec d(target: unknown, arg: ("a" | "b")[]);
// ~~ expected-token: ',' expected
// also doesn't work with a rest param
extern dec d(target: unknown, ...args: ("a" | "b")[]);
// ~~ expected-token: ',' expected
// also doesn't work in other mixedconstraint contexts like `extends` clauses
alias A<T extends ("a" | "b")[]> = ...;
// ~~ expected-token: ',' expected
// This also doesn't work, because the checker asserts that the constraint is syntactically an array _expression_
// before evaluating the mixed constraint in rest-constraint position. But this does work in other mixed constraint
// contexts.
extern dec d(target: unknown, ...args: Array<"a" | "b">);
// ~~~~~~~~~~~~~~~~ rest-parameter-array: A rest parameter must be of an array type.
This prevents writing functions/decorators that accept variadic type arguments where the valid types are those of an anonymous union.
There is a workaround. Declare an alias or a named union, then it can serve as the array item constraint:
union U {
"a",
"b",
}
// or
alias U = "a" | "b";
extern dec d(target: unknown, ...rest: U[]);
Checklist
Clear and concise description of the problem
Here are some things you cannot write in mixed constraint position that you might want to do for one reason or another:
This prevents writing functions/decorators that accept variadic type arguments where the valid types are those of an anonymous union.
There is a workaround. Declare an alias or a named union, then it can serve as the array item constraint:
Checklist