no-useless-constructor
禁止不必要的建構函式。
🔒
延伸 "plugin:@typescript-eslint/strict"
在 ESLint 設定 中啟用此規則。
此規則延伸了基本的 eslint/no-useless-constructor
規則。它增加了對以下內容的支援:
- 標記為
protected
/private
的建構函式(即將建構函式標記為非公開), - 當沒有父類別時,使用
public
建構函式, - 只有參數屬性的建構函式。
注意事項
此 Lint 規則將報告唯一目的是更改父建構函式可見性的建構函式。有關上下文,請參閱 關於此規則缺乏類型資訊的討論。
選項
請參閱 eslint/no-useless-constructor
選項。
使用方法
.eslintrc.cjs
module.exports = {
"rules": {
// Note: you must disable the base rule as it can report incorrect errors
"no-useless-constructor": "off",
"@typescript-eslint/no-useless-constructor": "error"
}
};
在 Playground 中試用此規則 ↗