react17, typescript에서
export interface LinesData{
lineId: string;
lineName: string;
cudsKey: string;
_checked: boolean;
}
정의하고

selectLineData: LinesData = []; 했는데

Type 'never[]' is missing 오류 해결해 주세요

에러 메시지 Type 'never[]' is not assignable to type 'LinesData'는 selectLineData를 배열로 초기화했는데, 타입을 단일 객체(LinesData)로 선언했기 때문입니다.

당신의 코드:

ts
복사
편집
export interface LinesData {
lineId: string;
lineName: string;
cudsKey: string;
_checked: boolean;
}

selectLineData: LinesData = []; // ❌ 오류 발생
이건 LinesData 타입에 배열을 대입했기 때문에 타입 불일치로 에러가 발생합니다.

✅ 해결 방법: 타입을 배열로 선언
selectLineData가 여러 개의 라인을 저장하는 배열이라면 다음과 같이 타입을 수정해야 합니다:

ts
복사
편집
selectLineData: LinesData[] = []; // ✅ 배열 타입으로 선언
참고: 단일 객체일 경우
만약 selectLineData가 단일 LinesData 객체라면, 빈 배열이 아니라 객체로 초기화해야 합니다:

ts
복사
편집
selectLineData: LinesData = {
lineId: '',
lineName: '',
cudsKey: '',
_checked: false
};

tag: none

댓글추가