영역별/JavaScript
Ts:두번째 변수
brandNuWs
2022. 5. 12. 17:34
// readonly는 실행은 가능하되 변수변경 불가
type player = {
readonly name:Name,
age?:Age
}
Ex)
nico.name = "jung" // error
Ex2)
const numbers: readonly number[] = [1, 2, 3, 4]
numbers.push(1) // error

Ex3)
//튜플
const player2: readonly [string, number, boolean] = ["nico", 1, true]
player2[0] = 1 // error -> 이중검증 (1) 0번째 index의 타입이 맞지않음 (2) readonly로 변경 보호
Ex4)
// null, undefined
let a : undefined = undefined
let b : null = null
Ex5)
// 타입스크립트에 보호를 다 벗어나고 싶을때
const a : any[] = [1, 2, 3, 4]
const b : any = true
a+b