This repository was archived by the owner on Apr 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1k
refactor(linting warnings): Fixed linting warnings #410
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,7 +14,7 @@ interface Props { | |
| darkModeController?: DarkModeController; | ||
| } | ||
|
|
||
| const Header = ({ darkModeController }: Props) => ( | ||
| const Header = ({ darkModeController }: Props): JSX.Element => ( | ||
| <nav className="nav"> | ||
| <div className="logo"> | ||
| <Link to="/"> | ||
|
|
@@ -56,7 +56,7 @@ const Header = ({ darkModeController }: Props) => ( | |
| <button | ||
| type="button" | ||
| className="dark-mode-toggle" | ||
| onClick={() => { | ||
| onClick={(): void => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @benhalverson Can we work on t/eslint together to avoid needing the obvious coercion… I know it is an acquired taste but |
||
| if (!darkModeController) | ||
| document.body.classList.toggle('dark-mode'); | ||
| }} | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 would recommend typing this as:
Not only is it a few characters shorter, but it also tells that the☺️
Headeris a React functional component, instead of just being a function that happens to conform to the interface of a functional componentThere 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.
Id welcome any guidance on typings with React, I dont actually know much about this at all honestly.
What Im seeing here is that because we are using a function expression we should document that expression returns a react functional component function, instead of just documenting the return type of that function itself.
I dont fully understand the benefits of this but I do think I understand the semantic difference.
Thank you for taking a look at this and bringing it up, Im very open to a discussion around the conventions we are using ❤️
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.
Thanks for the feedback @LinusU
Uh oh!
There was an error while loading. Please reload this page.
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.
Thanks @LinusU… react continues to impress me on how they fuzz TypeScript types :)
So I dug this out — https://unpkg.com/browse/@types/react@16.9.22/index.d.ts#L515:
Sure enough they wrapped an interface with a type as an alias, and sadly that means it will not type
… | (props: P) => JSX.Element | (props: P, context: any) => JSX.Elementwhich is really the developer facing type in all of this — sorry, deep breaths :)@jonchurch here is a good ref for react typing needs — https://github.com/typescript-cheatsheets/react-typescript-cheatsheet/blob/master/README.md#the-types-i-need-werent-exported
Q
do we want to bother retyping everything?
I honestly would not bother if it is not throwing… typing working for our needs, not React strict but still React.
So if we opt for it we will need to do work all over the place, and that can potentially break things or at least complicate other PRs
Q
do we really need
JSX.Elementcoercion?I honestly think it is always best to rely on TypeScripts inferred types unless you know for sure there is a glitch or preference… they do a good job nowadays that sometimes it is more accurate than coercion.
So doing it like this meant TypeScript inferred either JSX.Element or React.Element… not sure I can tell which with certainty as of current, but we can check out the code see what hovers.
@benhalverson — I just unresolved this conversation, let's figure out a game plan here then see if we need to create a new PR, push here and merge, or go the longer "task" issue route.