Skip to content

Non-homomorphic instantiation of a homomorphic mapped type is not spreadable when it has an array constraintΒ #56726

@Andarist

Description

πŸ”Ž Search Terms

mapped type homomorphic instantiation array tuple constraint spread spreadable

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried

⏯ Playground Link

https://www.typescriptlang.org/play?ts=5.4.0-dev.20231210#code/C4TwDgpgBAEghgOwCYBsIHkzAJYHsEDOAPOgHxQC8UA3gLABQUUA2gJJTYJQDWEIuAMyjoAugC4aDJkwBucFAFcIE9GxEBuKVAC+m+roYMkEAMYo4AJ2gCFCEznxQbdgIxEtAFSgQAHsAjIBFAASqa4FkhEAAoWuJAWoADSfAA0UFZwSPgoIFCIIMwipCkMpAAUAtgQKEgEEnSMLIkcXLz8Qh7iko1M5gBG1RIEwBacAOZ60lBxDoQSzAB0S-DIaJizxB7MiUUaWgb6AJQSHnoMJvjD6RAECijAlE62Ji5lDUxgsWD1Wr1wAygJAAiSoWYZAko9aZYPBzFi-aTvKbSOSKZRQFwAJgAzJDkTo8cikfjUUpgQJcLgIQimNpCUwRIS6VpcMAABYQCw-KH9QZQIEEMLIalQmawurwqFMYnI0nooF9Swi-HMqXdfGyeRkqAjJT06SqqaM-aQ7SHPRAA

πŸ’» Code

type HandleOptions<O> = {
  [I in keyof O]: {
    value: O[I];
  };
};

declare function func1<
  T extends Record<PropertyKey, readonly any[]>,
>(fields: {
  [K in keyof T]: {
    label: string;
    options: [...HandleOptions<T[K]>];
  };
}): T;

const result = func1({
  prop: {
    label: "first",
    options: [
      {
        value: 123,
      },
      {
        value: "foo",
      },
    ],
  },
  other: {
    label: "second",
    options: [
      {
        value: "bar",
      },
      {
        value: true,
      },
    ],
  },
});

πŸ™ Actual behavior

Error at line 12:

A rest element type must be an array type.(2574)

πŸ™‚ Expected behavior

The error should not be reported

Additional information about the issue

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions