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

Arrayable is unusable #952

Closed
fregante opened this issue Sep 2, 2024 · 4 comments · Fixed by #1003
Closed

Arrayable is unusable #952

fregante opened this issue Sep 2, 2024 · 4 comments · Fixed by #1003
Labels
bug Something isn't working

Comments

@fregante
Copy link
Collaborator

fregante commented Sep 2, 2024

Initially reported in #935 (comment)

In short:

  • function castArray<T>(a: Arrayable<T>): T[] is hard to type
    Demo
  • The code example in the type's source produces any[], losing the type information provided
    Demo
    Screenshot 1

cc @Max10240 let's continue here

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • The funding will be given to active contributors.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar
@fregante fregante added the bug Something isn't working label Sep 2, 2024
@Emiyaaaaa
Copy link
Collaborator

Emiyaaaaa commented Nov 30, 2024

Seems like a typescript bug about Array.isArray(readonly T[])
microsoft/TypeScript#17002

Maybe we can remove readonly? I think no one really want to pass a readonly array in.

@Max10240
Copy link
Contributor

Max10240 commented Dec 5, 2024

I agree. After all, it's called Arrayable , not ReadonlyArrayable😂

@Emiyaaaaa
Copy link
Collaborator

Emiyaaaaa commented Dec 5, 2024

I agree. After all, it's called Arrayable , not ReadonlyArrayable😂

But the reason for adding readonly is to support "all array"(Array and readonly Array), if we remove readonly, readonly Array will can not be passed in.

@Max10240
Copy link
Contributor

Max10240 commented Dec 5, 2024

Yes, I know that, which is why I was fine when @sindresorhus suggested I add the readonly modifier. But not being able to work with "Array.isArray" is really a big problem, and in general, I recommend removing "readonly".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants