Skip to content

Latest commit

 

History

History
64 lines (45 loc) · 1.47 KB

File metadata and controls

64 lines (45 loc) · 1.47 KB

require-exported-object-type

Require exported object constants to declare an explicit type annotation.

Rule Details

Property Value
Type suggestion
Fixable No
Recommended warn
Strict error

Rationale

Exported object constants become part of a module's public contract. Requiring an explicit annotation prevents large inferred structural types from leaking through exports and keeps the intended shape readable even when the value is wrapped in Object.freeze(...).

Examples

✅ Correct

export const StatusMap: Readonly<Record<string, string>> = Object.freeze({
  Active: 'active',
  Inactive: 'inactive',
});
type StatusLookup = Record<string, string>;

const StatusMap: StatusLookup = {
  Active: 'active',
};

export { StatusMap };

❌ Incorrect

export const StatusMap = Object.freeze({
  Active: 'active',
  Inactive: 'inactive',
});
const StatusMap = {
  Active: 'active',
};

export { StatusMap };

The rule only applies when the exported const initializer is an object literal or Object.freeze({ ... }). Calls such as Object.freeze() or Object.freeze(...values) are ignored because they do not expose a direct frozen object literal shape.

Configuration

This rule has no options:

'zero-tolerance/require-exported-object-type': 'error'