"가장 기본적인 narrowing tool. 모든 primitive 에 작동, 어디서나 켜져."
Value-level `typeof`
Foundations 트랙에서 회상: `typeof` 가 2 의미. Value-level `typeof` 가 runtime 에 돌고 7개 문자열 중 하나 반환: 'string', 'number', 'boolean', 'undefined', 'object', 'function', 'symbol', 'bigint'. (`null` 세면 8개 — 근데 typeof null === 'object', 유명한 JavaScript quirk.)
TypeScript 가 이 문자열 정확한 집합을 narrowing 연산으로 이해. if (typeof x === 'string') 그 분기 안에서 `x` 를 `string` 으로 narrow. 분기 밖에선 union 에서 `string` 뺀 거.
`typeof` 가 narrow 할 수 있는 거
7개 primitive 타입: `string`, `number`, `boolean`, `undefined`, `object`, `function`, `symbol`, `bigint`. 그게 전체 집합. 더 구체적인 거 (특정 object 모양, class instance, literal) 는 다른 narrowing tool 필요 — typeof 는 primitive layer 까지만 봐.
`typeof === 'object'` 함정
typeof null === 'object' 가 `true` 반환. 1995년 JavaScript 버그가 기능 됐어. `typeof x === 'object'` 로 narrow 하고 union 에 `null` 포함되면, 분기 안에 여전히 `null` 있어.
Fix: 명시 null 체크 추가. if (typeof x === 'object' && x !== null). TypeScript 가 narrowing 에 내장 — null 체크 후 `x` 가 non-null object 타입만이라는 거 알아.