Skip to content
← Back to rules

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

This rule is turned on by default when type-aware linting is enabled.
💭 This rule requires type information.

작동 방식

이 규칙은 합집합과 교집합의 타입 구성 요소 중 중복되는 것을 금지합니다.

왜 문제가 되는가?

타입스크립트의 타입 시스템 규칙에 따라 합집합 및 교집합 타입의 일부 구성 요소가 중복될 수 있습니다. 이러한 중복된 구성 요소는 추가적인 가치를 제공하지 않으며, 타입을 더 읽기 어렵고 이해하기 어렵게 만들 수 있습니다.

예시

이 규칙에 부적절한 코드 예시:

ts
// 합집합에서 unknown은 중복됨
type T1 = string | unknown;

// 합집합에서 any는 중복됨
type T2 = string | any;

// 합집합에서 never는 중복됨
type T3 = string | never;

// 다른 타입보다 넓은 리터럴 타입
type T4 = string | "hello";

// 부분 집합인 객체 타입
type T5 = { a: string } | { a: string; b: number };

이 규칙에 적절한 코드 예시:

ts
type T1 = string | number;

type T2 = "hello" | "world";

type T3 = { a: string } | { b: number };

// 교집합에서 unknown은 의미 있음
type T4 = string & unknown;

// 교집합에서 never는 의미 있음
type T5 = string & never;

사용 방법

구성 파일 또는 명령줄 인터페이스에서 이 규칙을 활성화하려면 다음을 사용할 수 있습니다:

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

참고 자료