-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
List: Parameterize generic type for item with any as default #8465
List: Parameterize generic type for item with any as default #8465
Conversation
My primary concern here is maintaining backwards-compatibility. I believe this change achieves that. However, if it does not then I am fine with targeting |
Agreed that with T = any, you'll probably be safe for compatibility. Someone else correct me if I'm wrong. |
Size Auditor did not detect a change in bundle size for any component! |
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.
🎉 Handy links: |
For anyone that may land here due to compiler errors, the solution is likely as follows: If you have previously defined your List's onRenderCell?: (item: Foo, index?: number, isScrolling?: boolean) => React.ReactNode; Where item of type onRenderCell?: (item?: Foo, index?: number, isScrolling?: boolean) => React.ReactNode; Also, in the body of the function you may want to guard against the case where item is This bug was previously masked by the usage of |
Pull request checklist
$ npm run change
Description of changes
I've found working with
List
and components that wrap it difficult as an end-user. This is partially because the backingitems
Array is typed asany[]
and therefore type-safety is lost for TypeScript developers.Last week on Shield, I watched a developer run into problems during a debug session as a result of this lack of type safety and thought it was worth fixing IFF backwards-compatibility could be maintained.
To reduce this barrier, I'm proposing that we parameterize the generic type for
List
'sitems
asT
which defaults toany
.This should maintain backwards compatibility as
item
anditems
will continue to be typed asany
if a parameterized type is omitted. If the type is provided, then the intellisense and other goodness should then be provided.Note: As part of our next major release we should look to remove the need for
any
as the default type.IDE Output
Here is a brief comparison of Code's intellisense before and after this change for the code snippet below:
Usage:
Before
onRenderCell
prop:items
prop:List
class definitionAfter
onRenderCell
prop:items
prop:List
class definitionFocus areas to test
Related to: #5557
Microsoft Reviewers: Open in CodeFlow