Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 31 |
Tags
- adb pair
- dvh
- 티스토리 성능
- vercel git lfs
- Git
- html
- device in use
- animation
- react-native
- ELECTRON
- silent printing
- Recoil
- ffi-napi
- camera permission
- react-native-dotenv
- github pdf
- Can't resolve
- github lfs
- rolldown
- electron-packager
- Failed to compiled
- Each child in a list should have a unique "key" prop.
- camera access
- adb connect
- github 100mb
- npm package
- 이미지 데이터 타입
- augmentedDevice
- nextjs
- custom printing
Archives
- Today
- Total
Bleeding edge
2022/12/07 - Any vs Unknown in Typescript 본문
Any vs Unknown
let unknownValueNum : unknown = 10;
let unknownValueStr : unknown = 'Test';
let anyValueNum : any = 10;
let anyValueStr : any = 'Test'
console.log(anyValueNum.length) //undefined
console.log(anyValueStr.length) //4
if(typeof unknownValueStr==="string"){
console.log(unknownValueStr.length) //4
}
console.log(unknownValueNum.length); // 'unknownValueNum' is of type 'unknown'.
console.log(unknownValueStr.length); // 'unknownValueStr' is of type 'unknown'.
언뜻보기에는 any와 unknown은 범위가 넓어보이니 용도가 같아보이지만, 위의 사례처럼 프로퍼티 또는 연산을 하는 경우 컴파일러가 체크한다
restProps와 같이 추가적인 속성이 들어올 수 있는 경우에는 다음과 같이 unknown[]를 사용하는 것이 좋다.(물론 사용하지 않는 경우라면 비워두는 것이 낫다)
export interface IA11yHiddenProps {
as?: string;
focusable?: boolean;
children?: string;
restProps: unknown[];
forwardedAs?: string | React.ComponentType<any>;
}'ConnecTo' 카테고리의 다른 글
| 2022/12/12 - SVG (0) | 2022.12.12 |
|---|---|
| 2022/12/08 - package.json module (1) | 2022.12.08 |
| 2022/12/06 - packagejson (0) | 2022.12.06 |
| 2022/12/05 - Bundler (0) | 2022.12.06 |
| 2022/12/02 (0) | 2022.12.05 |