Start using @typescript-eslint/no-unnecessary-condition eslint rule - #1200
Conversation
🦋 Changeset detectedLatest commit: e93fd15 The changes in this PR will be included in the next version bump. This PR includes changesets to release 7 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Looks like these are not equivalent, Shouldn't second be |
I agree they're not fully equivalent, however, for these type guard type of use cases, I think
Do you see any specific case where not having |
No, just wanted to make sure that we won't miss this. And I agree that we should not type check based on optional properties. |
There was a problem hiding this comment.
Pull request overview
This PR enables the @typescript-eslint/no-unnecessary-condition ESLint rule to eliminate unnecessary null/undefined checks and optional chaining operations. The changes primarily remove redundant type guards, replace object property checks with in operator, convert object-based maps to Map instances, and add explicit type annotations where the rule cannot infer mutability.
Changes:
- Removed unnecessary optional chaining (
?.) and nullish coalescing (??) operators where types guarantee non-null values - Replaced object property type guards (
obj.prop !== undefined) with theinoperator for better type narrowing - Converted plain object maps to
Mapinstances to avoid always-truthy object references - Added explicit boolean type annotations for variables modified in closures to work around rule limitations
Reviewed changes
Copilot reviewed 60 out of 60 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| eslint.base.config.js | Added the @typescript-eslint/no-unnecessary-condition rule configuration |
| packages/shared/src/shared/Metadata.ts | Made multiplicity required in RelationshipConstraint interface |
| packages/shared/src/shared/Values.ts | Changed Point2d/Point3d type guards to use in operator |
| packages/shared/src/test/MetadataProviderStub.ts | Converted schema stubs storage from object to Map |
| packages/testing/src/test/HierarchyBuilder.test.ts | Removed redundant optional chaining on opts parameter |
| packages/hierarchies-react/src/presentation-hierarchies-react/internal/UseUnifiedSelection.ts | Converted imodel selectables storage from object to Map |
| packages/hierarchies-react/src/presentation-hierarchies-react/stratakit/TreeRenderer.tsx | Removed unnecessary optional chaining and unused helper function |
| packages/hierarchies-react/src/presentation-hierarchies-react/UseTree.ts | Added explicit boolean type annotation for closure variable |
| packages/components/src/presentation-components/propertygrid/DataProvider.ts | Removed unnecessary null checks and added version compatibility comments |
| apps/test-app/frontend/src/index.tsx | Simplified promise array initialization by removing undefined check |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Added
@typescript-eslint/no-unnecessary-conditioneslint rule, which found a number of unnecessary checks, especially optional chaining and nullish coalescing.3 cases when I had to unnecessarily make changes to our code to overcome it:
Checking if object is of type, based on derived type attribute (usually in type guards):
Value changes in functions:
Object property access: