@sleavely/eslint-plugin-ts-rules
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

@sleavely/eslint-plugin-ts-rules

Installing

npm i --save-dev @sleavely/eslint-plugin-ts-rules
// .eslintrc.cjs
module.exports = {
  // ..
  plugins: [
    '@sleavely/ts-rules',
  ],
  rules: {
    '@sleavely/ts-rules/prefer-inferred-const': ['error', 'always'],
  }
}

Rules

ts-rules/prefer-inferred-const

A const variable should generally never change, and even if it does it should be contained within the same type, so inference can be used.

// ⛔
const name: string = 'foo'
// ✅
const name = 'foo'

// methods _should_ already define a return type or have an inferrable one
const getBurger = (): string => 'Big Mac'
// ⛔
const burger: string = getBurger()
// ✅
const burger = getBurger()

// Sometimes you may want to assign a custom type such as an enum. Use this approach in those cases:
const name = 'foo' as MyCustomTypeThatIsntAPrimitive

const name = 'foo' as const

Package Sidebar

Install

npm i @sleavely/eslint-plugin-ts-rules

Weekly Downloads

11

Version

1.0.0

License

MIT

Unpacked Size

3.92 kB

Total Files

6

Last publish

Collaborators

  • sleavely