| name | editor-interrogation |
| description | Use when debugging type inference. Use when types behave unexpectedly. Use when learning unfamiliar code. |
Use Your Editor to Interrogate and Explore the Type System
Overview
Your editor is your best TypeScript learning tool.
TypeScript's language services provide autocomplete, inspection, navigation, and refactoring. These aren't just conveniences - they're the primary way to understand what TypeScript thinks about your code.
When to Use This Skill
- Debugging unexpected type inference
- Understanding widening and narrowing behavior
- Exploring unfamiliar codebases
- Learning how libraries model their types
- Verifying that inferred return types match expectations
The Iron Rule
ALWAYS hover to verify types when behavior is unexpected.
Remember:
- Inferred types can differ from your expectations
- The editor shows what TypeScript ACTUALLY thinks
- "Go to Definition" reveals library type implementations
- Refactoring tools understand scope and imports
Detection: When to Interrogate
Check types when:
const num = 10;
const str = "hello";
function add(a: number, b: number) {
return a + b;
}
function process(x: string | null) {
if (x) {
x
}
}
Editor Inspection Techniques
Hover for Inferred Types
const list = [1, 2, 3];
const tuple = [1, 2, 3] as const;
Inspect Generics in Chains
const result = "a,b,c"
.split(",")
.map(Number)
.filter(n => n > 0);
Watch Narrowing in Branches
function example(x: string | number | null) {
if (typeof x === "string") {
x
} else if (x) {
x
} else {
x
}
}
"Go to Definition" for Library Types
Explore external types:
const response = await fetch('/api');
Refactoring Tools
Rename Symbol (F2)
Rename understands scope:
let i = 0;
for (let i = 0; i < 10; i++) {
console.log(i);
{
let i = 12;
console.log(i);
}
}
console.log(i);
Move Symbol to New File
- Automatically updates imports
- Works across the entire project
Extract Method/Variable
- Creates typed functions from selected code
- Preserves type information
Common Gotchas to Check
typeof null
function getElement(x: string | HTMLElement | null) {
if (typeof x === 'object') {
x
}
}
Optional Properties vs Undefined
interface Config {
name?: string;
}
const config: Config = {};
config.name
Array Index Access
const arr = [1, 2, 3];
arr[10]
Pressure Resistance Protocol
1. "I Know What the Type Is"
Pressure: "I don't need to hover, I know it's a string"
Response: Assumptions cause bugs. The editor shows truth.
Action: Hover anyway. 2 seconds to verify.
2. "Library Types Are Too Complex"
Pressure: "I can't understand these generic types"
Response: Click through one piece at a time. Follow the breadcrumbs.
Action: Use "Go to Definition" iteratively.
Red Flags - STOP and Check
- Type errors you don't understand
- Runtime errors that "shouldn't happen"
- Generic types that look wrong
- Narrowing that doesn't seem to work
Quick Reference
| Action | VS Code Shortcut |
|---|
| Hover for type | Mouse over symbol |
| Go to Definition | F12 or Cmd/Ctrl+Click |
| Find All References | Shift+F12 |
| Rename Symbol | F2 |
| Quick Fix | Cmd/Ctrl+. |
The Bottom Line
Your editor knows more about your types than you do.
When types behave unexpectedly, don't guess - inspect. Hover over symbols, follow definitions, and watch how types narrow. This builds intuition faster than any documentation.
Reference
Based on "Effective TypeScript" by Dan Vanderkam, Item 6: Use Your Editor to Interrogate and Explore the Type System.