Lab 10: Type Guards & Assertions
Step 1: Setup
docker run -it --rm node:20-alpine sh
npm install -g typescript ts-node
mkdir /lab10 && cd /lab10
cat > tsconfig.json << 'EOF'
{
"compilerOptions": {
"target": "ES2020",
"module": "commonjs",
"moduleResolution": "node",
"strict": true,
"esModuleInterop": true
}
}
EOFStep 2: User-Defined Type Guards (is)
Step 3: Generic Type Guards
Step 4: Assertion Functions
Step 5: The satisfies Operator
satisfies OperatorStep 6: Branded / Nominal Types
Step 7: Opaque Types Pattern
Step 8: Capstone — Full Type Safety Demo
Summary
Feature
Syntax
Purpose
Last updated
