영역별/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

'영역별 > JavaScript' 카테고리의 다른 글

Ts: call signature  (0) 2022.05.12
Ts:세번째 변수  (0) 2022.05.12
Ts:변수의 지정 및 재사용  (0) 2022.05.12
Js:변수 및 호이스팅  (0) 2022.05.04
가벼운 Js VS Ts  (0) 2022.05.03