TypeScript Compiler Options

keyofStringsOnly — Removed compiler option

Historically restricted keyof behavior for string index signatures. Modern keyof can include numeric and symbol keys; use Extract<keyof T, string> when an API genuinely accepts only string keys. Do not assume all property keys are strings. Deprecated in 5.0; no longer functional from 5.5. On the tested 5.8.3 compiler, enabling this option reports TS5102 even with ignoreDeprecations set to "5.0". Remove the entry rather than suppressing the error. The first example is intentionally invalid; the second is a separate migration project. Baseline: TypeScript 5.8.3. File labels are explanatory, not source text.

Formal Syntax & Structure

typescript syntaxtypescript
"keyofStringsOnly": true (historical, invalid on 5.8.3)

Parameters & Attributes

NameTypeDescription
keyofStringsOnlybooleanHistorical setting only; do not set in new projects.

Working Example

Example Snippettypescript
// File: tsconfig.json (omit this label){  "compilerOptions": {    "target": "ES2022",    "module": "CommonJS",    "strict": true,    "types": [],    "skipLibCheck": true,    "outDir": "dist",    "noEmitOnError": true,    "keyofStringsOnly": true  },  "files": [    "index.ts"  ]}// File: index.ts (omit this label)export const count: number = 7;// Run in a temporary project:// tsc -p . --pretty false// Expected: TS5102. The following separate project demonstrates migration.// File: tsconfig.json (omit this label){  "compilerOptions": {    "target": "ES2022",    "module": "CommonJS",    "strict": true,    "types": [],    "skipLibCheck": true,    "outDir": "dist",    "noEmitOnError": true  },  "files": [    "index.ts"  ]}// File: index.ts (omit this label)type Keys = Extract<keyof { name: string; 7: number }, string>;const key: Keys = "name";console.log(key);// Run: tsc -p . --pretty false
TypeScript Reference