readonly

nearworld·2022년 12월 6일
0

typescript

목록 보기
14/28
interface userSignUpSchema {
	readonly userId: string;
	readonly password: string;
}

const schema: userSignUpSchema = {
	userId: '',
	password: ''
};

/*
	에러[1]: 직접적인 값 변경 불가능
	에러 메세지: Cannot assign to 'userId' because it is a read-only property.
	동웅님: 값 변경할 일이 없다면 기본적으로 접근 제한자 readonly를 지정할 것
*/

schema.userId = 'example'; // 에러[1]
profile
깃허브: https://github.com/nearworld

0개의 댓글