✏️
eslintでTypeScriptの型定義をtypeからinterfaceに書き変える
を見て明日からinterfaceに変えたくなっただろうひと向け。
@typescript-eslint/consistent-type-definitionsを有効にする。
ESLint Flat Configの設定例
import tseslint from 'typescript-eslint';
import { defineConfig } from 'eslint/config';
export default defineConfig([
{
extends: tseslint.configs.recommended,
rules: {
// recommendedはデフォルトで有効ではない
'@typescript-eslint/consistent-type-definitions': ['error', 'interface'],
},
},
]);
fixコマンドで書き換えてくれます。
eslint . --fix
その他
- tseslint.configは非推奨です
https://typescript-eslint.io/packages/typescript-eslint/#config-deprecated - 今回の記事で利用したライブラリのバージョン
- eslint: 9.37.0
- typescript-eslint: 8.46.1
Discussion