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.
fix(eslint-plugin): [explicit-function-return-type] support JSX attributes in
allowTypedFunctionExpressions
#7553New 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(eslint-plugin): [explicit-function-return-type] support JSX attributes in
allowTypedFunctionExpressions
#7553Changes from all commits
56cfcca
52ff72c
a4df798
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
This is technically the relevant RHS type of
JSXAttribute
, so this check could also recurse one level higher if that is preferred. This should be the only way to directly supply a function in JSX though.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 think we'll want to check the parent because this is another valid location for a
JSXExpressionContainer
: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.
@bradzacher Ah, I totally forgot about the render-props pattern, it's been a while since their heyday! Running this down actually led me across an existing issue in TS where fragment shorthands are not typed properly: microsoft/TypeScript#50429
I went around on this for a while, but I again think all
JSXExpressionContainer
instances are fully bound by types barring that issue (reference CodeSandbox with render props):<Fragment />
: not allowed due to limited child types (JSX.ElementType
orJSX.Element | null
); all functions will be type errors here<>
fragment shorthand: all functions should be type errors herechildren
prop, the same as if children was defined via attributeI eventually realized that while something like this is unsafe:
Having a lint error that turns it into this doesn't make things better as it's still not a type error but won't work as expected at runtime (especially if you return an object instead):
While this is a currently an issue with TypeScript, it doesn't seem like the lint rule can do anything better here in place of proper type-checking. But functions can be valid in children expression containers generally.
Reference TS-ESLint playground
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.
DRYing these out, it makes it more obvious that the recursive object-property case doesn't include this
isConstructorArgument()
case, but it seems like it should?Happy to move it into
isTypedParent()
and add tests if this is indeed a bug.