Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/eslint-plugin-react-hooks/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ const configs = {
plugins,
rules: recommendedLatestRuleConfigs,
},
flat: {} as {
recommended: ReactHooksFlatConfig;
'recommended-latest': ReactHooksFlatConfig;
flat: {
recommended: null as unknown as ReactHooksFlatConfig,
'recommended-latest': null as unknown as ReactHooksFlatConfig,
Comment on lines +75 to +76
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Double type assertion hides runtime nullability

Using null as unknown as ReactHooksFlatConfig is a double type assertion (escape hatch through unknown) that tells TypeScript these properties are fully-initialized ReactHooksFlatConfig objects at all times, while their runtime value is actually null until the Object.assign call on line 89 replaces them.

In practice this is safe because Object.assign(configs.flat, {...}) runs synchronously before the module is exported, so no consumer can ever observe the null values. However, null as unknown as T is a stronger bypass than necessary and entirely suppresses null-safety guarantees from the type system for these properties.

A slightly less aggressive alternative that avoids null in the object entirely would be:

  flat: {
    recommended: {} as ReactHooksFlatConfig,
    'recommended-latest': {} as ReactHooksFlatConfig,
  },

This keeps a plain single-level cast (same pattern used elsewhere in the file for basicRuleConfigs) and avoids the runtime null, while still giving TypeScript concrete property keys to work with — which is the root cause of the original error.

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/eslint-plugin-react-hooks/src/index.ts
Line: 75-76

Comment:
**Double type assertion hides runtime nullability**

Using `null as unknown as ReactHooksFlatConfig` is a double type assertion (escape hatch through `unknown`) that tells TypeScript these properties are fully-initialized `ReactHooksFlatConfig` objects at all times, while their runtime value is actually `null` until the `Object.assign` call on line 89 replaces them.

In practice this is safe because `Object.assign(configs.flat, {...})` runs synchronously before the module is exported, so no consumer can ever observe the `null` values. However, `null as unknown as T` is a stronger bypass than necessary and entirely suppresses null-safety guarantees from the type system for these properties.

A slightly less aggressive alternative that avoids `null` in the object entirely would be:

```typescript
  flat: {
    recommended: {} as ReactHooksFlatConfig,
    'recommended-latest': {} as ReactHooksFlatConfig,
  },
```

This keeps a plain single-level cast (same pattern used elsewhere in the file for `basicRuleConfigs`) and avoids the runtime `null`, while still giving TypeScript concrete property keys to work with — which is the root cause of the original error.

How can I resolve this? If you propose a fix, please make it concise.

Fix in Claude Code Fix in Codex

},
};

Expand Down
Loading