Repository navigation
[Fix] static-property-placement: don't report a typed context field - #4060
Merged
ljharb merged 2 commits intoNov 3, 2026
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #4060 +/- ##
=======================================
Coverage 97.74% 97.75%
=======================================
Files 137 137
Lines 10299 10296 -3
Branches 3834 3832 -2
=======================================
- Hits 10067 10065 -2
+ Misses 232 231 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
b84330808
force-pushed
the
static-property-placement-typed-context
branch
from
October 24, 2026 09:21
2dd0415 to
70b8070
Compare
…ops` instance field as `propTypes`
`isContextTypesDeclaration` returned true for any class field named `context` that has a type annotation. That branch was marked "Flow support" and was copied from the `props` check in `isPropTypesDeclaration`, but a typed `context` field declares the type of `this.context`, not `contextTypes`. So TypeScript's `declare context: React.ContextType<typeof MyContext>` was reported as "'contextTypes' should be declared as a static class property." Only a property named `contextTypes` counts as a contextTypes declaration now. Fixes jsx-eslint#3467 Co-authored-by: b84330808 <[email protected]> Co-authored-by: Jordan Harband <[email protected]> Assisted-By: Claude Opus 5.5 <[email protected]>
ljharb
force-pushed
the
static-property-placement-typed-context
branch
from
November 3, 2026 19:44
70b8070 to
ea87c86
Compare
ljharb
approved these changes
Nov 3, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #3467
static-property-placementreportsdeclare context: React.ContextType<typeof MyContext>(the usual way to typethis.contextin a TS class component) as "'contextTypes' should be declared as a static class property."The cause is the "Flow support" branch in
isContextTypesDeclaration(lib/util/props.js), which returned true for any class field namedcontextwith a type annotation. A typedcontextfield declares the type ofthis.context, notcontextTypes, so this removes that branch, as agreed in the issue.forbid-prop-typeswithcheckContextTypesuses the same helper, so it also stops treating an annotatedcontextinstance field ascontextTypes.Tests: valid cases for
declare contextnext tostatic contextTypeand next tostatic contextTypes, plus a plain annotatedcontext:field. They fail without the change.Side note: the matching
propsbranch inisPropTypesDeclarationmakes this rule reportprops: Props;/declare props: Props;as a misplacedpropTypestoo. I left it alone because the prop-types rules rely on it for Flow, but I can follow up if you'd like this rule to handle it.I used Claude Code to write this change.