Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Andarist opened this issue Dec 10, 2023 · 0 comments Β· Fixed by #56727 or #57122
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@Andarist
Copy link
Contributor

πŸ”Ž 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

@RyanCavanaugh RyanCavanaugh added Help Wanted You can do this Possible Improvement The current behavior isn't wrong, but it's possible to see that it might be better in some cases labels Dec 11, 2023
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Dec 11, 2023
@gabritto gabritto reopened this Jan 19, 2024
@ahejlsberg ahejlsberg modified the milestones: Backlog, TypeScript 5.4.0 Feb 16, 2024
@ahejlsberg ahejlsberg added Bug A bug in TypeScript and removed Help Wanted You can do this Possible Improvement The current behavior isn't wrong, but it's possible to see that it might be better in some cases labels Feb 16, 2024
@ahejlsberg ahejlsberg self-assigned this Feb 16, 2024
@typescript-bot typescript-bot added the Fix Available A PR has been opened for this issue label Feb 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Projects
None yet
5 participants