-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
fix(useVirtualList): allow readonly arrays as input #4504
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
fix(useVirtualList): allow readonly arrays as input #4504
Conversation
|
||
it('allows a readonly array as input', () => { | ||
const input = ['a', 'b', 'c', 'd', 'e', 'f'] as const | ||
const { list } = useVirtualList(ref(input), { itemHeight: () => 50, overscan: 1 }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why ref this here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was just copying the other tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure if this is right.
tests are failing too btw 😄
@@ -42,7 +42,7 @@ export interface UseVirtualListItem<T> { | |||
} | |||
|
|||
export interface UseVirtualListReturn<T> { | |||
list: Ref<UseVirtualListItem<T>[]> | |||
list: Ref<readonly UseVirtualListItem<T>[]> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I'll fix this up.
039e839
to
3da46e8
Compare
3da46e8
to
9a55d4d
Compare
I reworked this PR. It should be good now. |
i'm not sure you need to go this far. a writable array is assignable to a readonly array because of this, it should be as simple as changing see this playground importantly, the writable ones are what we have now and the readonly ones are what im suggesting |
Interesting. Do you have a link to where those issues were mentioned? I couldn't find them unless I'm being blind Would be good to understand for future references why we wouldn't use readonly |
Ahh, actually, the more simple approach will work in this case. I over-fixed things. Should I change this to do the more simple approach? The issue in question was related to readonly coming through in the return type. Here's a code snippet showing the issue: |
af1ac06
to
ed7cdf8
Compare
ed7cdf8
to
e7a7f80
Compare
Before submitting the PR, please make sure you do the following
fixes #123
).Description
Fix #4503
Allow passing a
ReadonlyArray
touseVirtualList
.