Enforce a single, strict naming convention for TypeScript generic type parameters using ESLint, and migrate the rule to error after a short “warn” rollout.
Rules:
PascalCase for type parameters.T or a PascalCase identifier such as TUser, TItem2).warn, then switch to error once the codebase is compliant.Example ESLint config:
// .eslintrc.cjs
module.exports = {
rules: {
'@typescript-eslint/naming-convention': [
'error', // start as 'warn' for gradual rollout
{
selector: 'typeParameter',
format: ['PascalCase'],
leadingUnderscore: 'forbid',
trailingUnderscore: 'forbid',
custom: {
regex: '^(T|T[A-Z][A-Za-z]+[0-9]*|[A-Z][a-zA-Z]+[0-9]*)$',
match: true,
},
},
],
},
}
Apply this to every generic type parameter (<TUser>, <TData2> etc.) so the meaning of identifiers stays consistent and automatically enforced across the codebase.