/* regression tests */ function rest_array(...xs: Array): T { // Ok, arrays can be rest params return xs[0]; } function rest_tuple(...xs: [T]): T { // Ok, tuples can be rest params return xs[0]; } function rest_ro_array(...xs: $ReadOnlyArray): T { // Ok return xs[0]; } function rest_any(...xs: any): any { // Ok, any can be a rest param return xs[0]; } function rest_t>(...xs: T): U { // Ok, bounded targ can be rest return xs[0]; } // These are ok bounds for the rest param function unbound_rest_t(...xs: T): void {} function mixed_rest_t(...xs: T): void {} function array_rest_t>(...xs: T): void {} function roarray_rest_t>(...xs: T): void {} function iterable_rest_t>(...xs: T): void {} function empty_rest_t(...xs: T): void {} function bounds_on_bounds() { return function(...xs: T): void {} } // These are bad bounds for the rest param function bad_unbound_rest_t(...xs: T): T { return xs.pop(); // Error - no bound on T } function string_rest_t(...xs: T): void {} // Error - rest param can't be a string function empty_rest_t(...xs: T): void {} // Error - rest param can't be empty type Rest = Array; function rest_alias(...xs: Rest): void {} // Ok function rest_union(...xs: [1,2] | Array): number { // OK return xs[0]; } function rest_intersection(...xs: { x: number } & [1,2]): number { // OK return xs[0] + xs.x; } function empty_rest>(...xs: T): T { return xs; } (empty_rest(): empty); // Error Array ~> empty function return_rest_param>( f: (...args: Args) => void, ): (...args: Args) => number { return function(...args) { return args; // Error: Array ~> number } } function requires_first_param(x: number, ...rest: Array): void {} requires_first_param(); // Error: missing first arg