C, C++
자바스크립트
1) 명시적 정의
let b : boolean = "x" //불가능
let b : string = "x" //가능
키워드 + 변수명 : 타입 = 할당하는 값 (명시)
2) 암묵적 정의 : 이걸 선호
let a = "hello" //typescript는 a가 string 타입이라는 것을 추론할 수 있다
a = "bye" //가능
a = 1 //불가능 (string -> int), 자바스크립트는 가능
let c = [1,2,3]
c.push("1") //불가능. c : int[]로 타입스크립트가 추론
let c = [] //int로 하려면 let c: number[] = []처럼 명시적으로 해야 한다
c.push("1")
const player = {
name : "nico"
}
player.name = 1//error : 이미 string으로 추론
player.hello()//error : 없으니까
키워드 + 변수명 = 할당하는 값 (추론)