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

Typescript conversion: app/component/FileIndex #724

Merged

Conversation

lsparlin
Copy link
Contributor

@lsparlin lsparlin commented Oct 18, 2022

Linked Issue

Description

Migrate src/component/FileIndex.js to typescript.

export FileListItem from PostList for type-checking

Methodology

Code of Conduct

By submitting this pull request, you agree to follow our Code of Conduct

@netlify
Copy link

netlify bot commented Oct 18, 2022

👷 Deploy Preview for virtual-coffee-io processing.

Name Link
🔨 Latest commit 88121a0
🔍 Latest deploy log https://app.netlify.com/sites/virtual-coffee-io/deploys/63529652398afa0008330725

Copy link
Member

@danieltott danieltott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @lsparlin !

I have a couple changes here.

The as FileListItem[] is perfect for the second reduce parameter, but it's actually hiding some issues when using it in the body (lines 40, 53, and 72). We should assign types to those returned variables normally so that typescript can do type checking - when you use as, we're basically promising we're matching the type and telling typescript to not check them at all.

Once you do this, you'll see that we need to adjust the type definitions - since children can be null.

Let me know if you have any questions about this!

Copy link
Member

@danieltott danieltott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @lsparlin!!

Just as a note - I remembered this just now while reviewing, for reducers we can actually send the type of the initial value / accumulator param as a generic to reduce like this: files.reduce<FileListItem[]> - that way we don't need to use as at all! I made this change, I just wanted to let you know about it 👍🏼

@danieltott danieltott merged commit 748f794 into Virtual-Coffee:main Oct 21, 2022
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

Successfully merging this pull request may close these issues.

Convert FileIndex.jsx to TypeScript
2 participants