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

Merge / Concat const arrays #32006

Closed
4 tasks done
benneq opened this issue Jun 20, 2019 · 2 comments
Closed
4 tasks done

Merge / Concat const arrays #32006

benneq opened this issue Jun 20, 2019 · 2 comments

Comments

@benneq
Copy link

benneq commented Jun 20, 2019

Search Terms

const array concat merge

Suggestion

Merging const arrays should result in a new const array

Use Cases

Convenience

Examples

const ARR1 = ['a', 'b'] as const; // type is: readonly ['a', 'b']
const ARR2 = ['x', 'y'] as const; // type is: readonly ['x', 'y']

const CONCAT = [...ARR1, ...ARR2] as const; // type is: readonly ('a', 'b', 'x', 'y')[]
// but should be: readonly ['a', 'b', 'x', 'y']

Checklist

My suggestion meets these guidelines:

  • [?] This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.
@AnyhowStep
Copy link
Contributor

I think there's an issue somewhere here that also asks for this, but I can't remember where.

I would personally also like this because the current way of emulating this with recursive types, or conditional types (or both) is clunky, and makes you reach the max instantiation depth sooner

@AnyhowStep
Copy link
Contributor

#26058

I know there are other issues also asking for this but this is the only one I could find on mobile

@benneq benneq closed this as completed Jun 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants