typescript/array-type 스타일
작동 방식
배열에 대해 T[] 또는 Array<T> 중 하나를 일관되게 사용하도록 요구합니다.
왜 문제가 될까?
Array 타입을 직접 사용하는 것은 비표준적인 스타일입니다. 대신 배열 타입으로 T[] 또는 Array<T>를 사용하세요.
예시
이 규칙에 부적절한 코드 예시:
typescript
/*oxlint array-type: ["error", { "default": "array" }] */
const arr: Array<number> = new Array<number>();typescript
/*oxlint array-type: ["error", { "default": "generic" }] */
const arr: number[] = new Array<number>();typescript
/*oxlint array-type: ["error", { "default": "array-simple" }] */
const a: (string | number)[] = ["a", "b"];
const b: { prop: string }[] = [{ prop: "a" }];
const c: Array<MyType> = ["a", "b"];
const d: Array<string> = ["a", "b"];이 규칙에 적절한 코드 예시:
typescript
/*oxlint array-type: ["error", { "default": "array" }] */
const arr: number[] = new Array<number>();typescript
/*oxlint array-type: ["error", { "default": "generic" }] */
const arr: Array<number> = new Array<number>();typescript
/*oxlint array-type: ["error", { "default": "array-simple" }] */
const a: Array<string | number> = ["a", "b"];
const b: Array<{ prop: string }> = [{ prop: "a" }];
const c: string[] = ["a", "b"];
const d: MyType[] = ["a", "b"];구성
이 규칙은 다음 속성을 가진 구성 객체를 수용합니다.
default
type: "array" | "array-simple" | "generic"
기본값: "array"
가변 상황에서 기대되는 배열 타입입니다.
readonly
type: "array" | "array-simple" | "generic"
기본값: null
읽기 전용 상황에서 기대되는 배열 타입입니다. 생략할 경우, default의 값이 사용됩니다.
사용 방법
이 규칙을 구성 파일이나 명령줄 인터페이스에서 활성화하려면 다음과 같이 사용할 수 있습니다:
json
{
"rules": {
"typescript/array-type": "error"
}
}bash
oxlint --deny typescript/array-type