eslint-plugin-ts-inline-parameter-types
v1.0.1
Published
ESLint plugin to enforce inline TypeScript types in function parameters
Maintainers
Readme
eslint-plugin-ts-inline-parameter-types
ESLint plugin that flags single-use type definitions in function parameters.
Installation
npm install -d eslint-plugin-ts-inline-parameter-types
# bun add -d eslint-plugin-ts-inline-parameter-typesimport tsInlineParameterTypes from 'eslint-plugin-ts-inline-parameter-types';
export default [
{
plugins: {
'ts-inline-parameter-types': tsInlineParameterTypes,
},
rules: {
'ts-inline-parameter-types/prefer-inline-type-parameters': 'warn',
},
},
];Rule: prefer-inline-type-parameters
Warns when a type is defined separately but only used once in a function parameter.
❌ Incorrect
type UserProps = {
name: string;
age: number;
};
const User = ({ name, age }: UserProps) => {
return <div>{name}</div>;
};interface Config {
apiUrl: string;
timeout: number;
}
function initApi(config: Config) {
return config.apiUrl;
}✅ Correct
const User = ({ name, age }: {
name: string;
age: number;
}) => {
return <div>{name}</div>;
};function initApi(config: {
apiUrl: string;
timeout: number;
}) {
return config.apiUrl;
}Auto-fix handles this transformation automatically.
Skipped cases
Type is reused
type UserProps = {
name: string;
};
const UserA = ({ name }: UserProps) => <div>{name}</div>;
const UserB = ({ name }: UserProps) => <span>{name}</span>;Type is exported
export type UserProps = {
name: string;
};
export const User = ({ name }: UserProps) => {
return <div>{name}</div>;
};Type used in non-parameter context
type Config = {
enabled: boolean;
};
const config: Config = { enabled: true };Type used in multiple contexts
type Config = {
enabled: boolean;
};
const config: Config = { enabled: true };
function updateConfig(newConfig: Config) {
// ...
}Development
bun install
bun test
bun run format
bun run lintLicense
MIT
