typescript Type Inference 타입추론
📌 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
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.
Author And Source
이 문제에 관하여(typescript Type Inference 타입추론), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@ash3767/typescript-Type-Inference-타입추론저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)