{"record":{"id":"3e339d34c85a815e","repo":"oxc-project/oxc","slug":"an-index-signature-is-preferred-over-a-record","errorCode":null,"errorMessage":"An index signature is preferred over a record.","messagePattern":"An index signature is preferred over a record\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/typescript/consistent_indexed_object_style.rs","lineNumber":36,"sourceCode":"    rule::{DefaultRuleConfig, Rule},\n};\n\nfn consistent_indexed_object_style_diagnostic(\n    preferred: ConsistentIndexedObjectStyleConfig,\n    span: Span,\n) -> OxcDiagnostic {\n    let (warning_message, help_message) = match preferred {\n        ConsistentIndexedObjectStyleConfig::Record => (\n            \"A record is preferred over an index signature.\",\n            \"Use a record type such as `Record<string, unknown>` instead of an index signature.\",\n        ),\n        ConsistentIndexedObjectStyleConfig::IndexSignature => (\n            \"An index signature is preferred over a record.\",\n            \"Use an index signature such as `{ [key: string]: unknown }` instead of a record type.\",\n        ),\n    };\n\n    OxcDiagnostic::warn(warning_message).with_help(help_message).with_label(span)\n}\n\n#[derive(Debug, Clone, Default, Deserialize)]\npub struct ConsistentIndexedObjectStyle(ConsistentIndexedObjectStyleConfig);\n\n#[derive(Debug, Default, Clone, Copy, Eq, PartialEq, Deserialize, Serialize, JsonSchema)]\n#[serde(rename_all = \"kebab-case\")]\nenum ConsistentIndexedObjectStyleConfig {\n    /// When set to `record`, enforces the use of a `Record` for indexed object types, e.g. `Record<string, unknown>`.\n    #[default]\n    Record,\n    /// When set to `index-signature`, enforces the use of indexed signature types, e.g. `{ [key: string]: unknown }`.\n    IndexSignature,\n}\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/typescript/consistent_indexed_object_style.rs#L18-L54","documentation":"Warning from typescript/consistent-indexed-object-style (crates/oxc_linter/src/rules/typescript/consistent_indexed_object_style.rs:36). With the option 'index-signature', keyed types must use index-signature syntax; it fires on Record<K, V> usages and tells you to write '{ [key: string]: unknown }' instead.","triggerScenarios":"oxlint runs with 'consistent-indexed-object-style': ['error', 'index-signature'] and the file contains 'type Dict = Record<string, unknown>', a parameter 'opts: Record<number, Foo>', or a nested Record inside another type.","commonSituations":"Codebases standardized on index signatures (often older or Angular-era conventions) enabling this non-default option; tooling that generates Record types being introduced into such a codebase; documentation examples using Record pasted into the project.","solutions":["Rewrite Record<K, V> as '{ [key: K]: V }' (e.g. '{ [key: string]: unknown }')","For Record with union keys like Record<'a'|'b', X>, map to explicit members or keep Record and disable per line with an explanation, since a plain index signature cannot express finite key unions","If Record is the preferred house style, drop the custom option and use the default"],"exampleFix":"// before\ntype Dict = Record<string, unknown>;\n\n// after\ntype Dict = { [key: string]: unknown };","handlingStrategy":"validation","validationCode":"const RECORD = /:\\s*Record\\s*</;\nfor (const line of source.split('\\n')) {\n  if (RECORD.test(line)) fail('Record used; prefer an index signature (style: index-signature)', line);\n}","typeGuard":"function isStringIndex(o: object): o is { [key: string]: unknown } {\n  return Object.keys(o).every((k) => typeof k === 'string');\n}","tryCatchPattern":null,"preventionTips":["Only choose index-signature style deliberately and record it in .oxlintrc.json","For finite key unions use explicit members instead of forcing Record","Grep for 'Record<' during review when this style is active"],"tags":["typescript","oxlint","lint","record-type","index-signature","style"],"backgroundTag":"record-vs-index-signature","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}