"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 } }