typescript Type Inference 타입추론

BackEnd_Ash.log·2021년 8월 18일
0

typescript

목록 보기
14/17

📌 base type inference

export {};

let bool = true;
const arr = [1, 2, 3];
const tuple = [true, 1];
bool = 1; // error!

let v1 = 123;
let v2 = 'abc';
v1 = 'a'; // error
v2 = 456; // error

this is because of type inference

✅ typeof

export {};

const v1 = 123;
const v2 = "abc";
let v3: typeof v1 = 234; // const v1 : 123;

if you typeof , declared more strictly

of course you have to write the type if you want, but type inference is possible.

profile
꾸준함이란 ... ?

0개의 댓글