Skip to content

"So farewell, TypeScript. May you bring much rigor and satisfaction to your tribe while letting the rest of us enjoy JavaScript in the glorious spirit it was originally designed: Free of strong typing" β€” David Heinemeier Hansson

Disallow gymnastics needed to please the TS compiler (no-ts) ​

πŸ’Ό This rule is enabled in the following configs: 🌐 all, βœ… recommended.

πŸ”§ This rule is automatically fixable by the --fix CLI option.

πŸ“– Rule details ​

Prevent type annotations in your code.

πŸ’‘ Examples ​

ts
// ❌ Incorrect
function tsAdd(a: number, b: number): number
function tsAdd(a: string, b: string): string
function tsAdd<T extends any[]>(a: T, b: T): T
function tsAdd(a: any, b: any): any {
  if (typeof a === 'string' && typeof b === 'string') return a + b
  if (typeof a === 'number' && typeof b === 'number') return a + b
  if (Array.isArray(a) && Array.isArray(b)) return [...a, ...b]
  throw new Error('invalid types!')
}

tsAdd(1, 2)
tsAdd('a', 'b')
tsAdd([1, 2], [3, 4])

// βœ… Correct
const add = (a, b) => a + b
add(1, [2, 3])

πŸ”§ Config ​

js
{ rules: { 'ninja/no-ts': 2 } }

πŸ§‘β€πŸ’» Demo ​

Released under the MIT License