import * as Arr from '../api/Arr';
import * as Fun from '../api/Fun';

export const Immutable = <T = Record<string,() => any>>(...fields: string[]) => {
  return function(...values: any[]): T {
    if (fields.length !== values.length) {
      throw new Error('Wrong number of arguments to struct. Expected "[' + fields.length + ']", got ' + values.length + ' arguments');
    }

    const struct: Record<string,() => any> = {};
    Arr.each(fields, function (name, i) {
      struct[name] = Fun.constant(values[i]);
    });
    return <any>struct;
  };
};
import * as Arr from '../api/Arr';
import * as Fun from '../api/Fun';

export const Immutable = <T extends string>(...fields: T[]) => {
  return function(...values): {
    [key in T]: () => any
  } {
    if (fields.length !== values.length) {
      throw new Error('Wrong number of arguments to struct. Expected "[' + fields.length + ']", got ' + values.length + ' arguments');
    }

    const struct = {} as {[key in T]: () => any};
    Arr.each(fields, function (name, i) {
      struct[name] = Fun.constant(values[i]);
    });
    return struct;
  };
};
Revert most of the changes to Struct.immutable as the original was better
TINY-1755: Revert most of the changes to Struct.immutable as the original was better
