[타입스크립트] 타입스크립트의 타입은 변하지 않습니다!


[타입스크립트] 타입스크립트의 타입은 변하지 않습니다!

자바스크립트에서는 한 변수가 다양한 타입을 가지고 다양한 목적으로 사용됩니다. // 자바스크립트 let id = "12-34-56"; fetchProduct(id); // id는 string id = 123456; fetchProductBySerialNumber(id); // id는 number 자바스크립트로 작성되었기 때문에 id는 string으로도 사용되었고 number로도 사용되었습니다. // 타입스크립트 let id = "12-34-56"; fetchProduct(id); id = 123456; // error: Type 'number' is not assignable to type 'string'. fetchProductBySerialNumber(id); // error: Argument of type 'string' is not assignable // to parameter of type 'number'. 타입스크립트는 id를 처음 선언할 때 "12-34-56"을 보고 ...


#effectivetypescript #typescript #이펙티브타입스크립트 #타입스크립트

원문링크 : [타입스크립트] 타입스크립트의 타입은 변하지 않습니다!