Skip to content
← Back to rules

typescript/no-duplicate-type-constituents 정확성

This rule is turned on by default when type-aware linting is enabled.
💭 This rule requires type information.
An auto-fix is available for this rule.

해당 규칙의 기능

이 규칙은 유니언 또는 인터섹션 타입의 중복 구성 요소를 허용하지 않습니다.

왜 문제가 되는가?

유니언 및 인터섹션 타입 내의 중복 구성 요소는 아무런 목적도 없으며 코드를 더 복잡하게 만들 수 있습니다. 이러한 경우는 실수일 가능성이 높습니다.

예시

이 규칙에 잘못된 코드 예시:

ts
type T1 = "A" | "A";

type T2 = A | A | B;

type T3 = { a: string } & { a: string };

type T4 = [A, A];

type T5 = "foo" | "bar" | "foo";

이 규칙에 올바른 코드 예시:

ts
type T1 = "A" | "B";

type T2 = A | B | C;

type T3 = { a: string } & { b: string };

type T4 = [A, B];

type T5 = "foo" | "bar" | "baz";

설정

이 규칙은 다음 속성을 가진 설정 객체를 수용합니다.

ignoreIntersections

type: boolean

기본값: false

인터섹션 타입 내 중복 타입을 무시할지 여부입니다.
true로 설정 시 type T = A & A를 허용합니다.

ignoreUnions

type: boolean

기본값: false

유니언 타입 내 중복 타입을 무시할지 여부입니다.
true로 설정 시 type T = A | A를 허용합니다.

사용 방법

설정 파일 또는 명령줄 인터페이스를 통해 이 규칙을 활성화하려면 다음을 사용하세요:

json
{
  "rules": {
    "typescript/no-duplicate-type-constituents": "error"
  }
}
bash
oxlint --type-aware --deny typescript/no-duplicate-type-constituents

참고자료