Skip to content

type-generic-spacing ​

Enforces consistent spacing inside TypeScript type generics.

Rule Details ​

This rule enforces consistent spacing inside TypeScript type generics.

Options ​

This rule takes an object argument with before and after properties, each with a Boolean value.

The default configuration is { "before": false, "after": false }.

true means there should be one or more spaces and false means no spaces.

Examples of incorrect code for this rule:

ts
/* eslint @stylistic/type-generic-spacing: ["error"] */

type Foo
<T = true> = T
const foo: Array
<number> = []
function foo
<T> () {}
const value = callback
<string>
()
const set = new Set
<string>
()
const tagged = tag
<string>
`value`
interface Log { new <T>
(): Log
foo
<T>
(name: T): void
call: <T>
() => void
construct: new <T>
() => Log
}
incorrect

Examples of correct code for this rule:

ts
/* eslint @stylistic/type-generic-spacing: ["error"] */

type Foo<T = true> = T

const foo: Array<number> = []

function foo<T>() {}

const value = callback<string>()

const set = new Set<string>()

const tagged = tag<string>`value`

interface Log {
  new <T>(): Log
  foo<T>(name: T): void
  call: <T>() => void
  construct: new <T>() => Log
}
correct

Changelog ​

v6.0.0-beta.5 on

v5.6.0 on

  • fixaa0c6acignore spaces after new in TSConstructorType (#1044)

v5.3.0 on

  • fix84fa86aallow spaces between class and generic (#927)

Released under the MIT License.