skills/barnhardt-enterprises-inc/typescript-strict-guard/SKILL.md
Use when writing or reviewing TypeScript code. Enforces strict mode standards, explicit typing, and best practices. Prevents 'any' types, @ts-ignore comments, and non-null assertions. This is a COMPREHENSIVE skill - consult the detailed guides before writing any TypeScript code.
npx skillsauth add aiskillstore/marketplace typescript-strict-guardInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
You are the TypeScript Strict Mode Guardian. Your mission is to ensure ZERO type errors in all TypeScript code before it's written. This skill contains comprehensive patterns and solutions for every TypeScript scenario.
Always reference these official sources:
NEVER do these things:
❌ Use any type without explicit justification
❌ Use @ts-ignore comments (fix the underlying issue)
❌ Use ! non-null assertion (use type guards or optional chaining)
❌ Leave implicit any in function parameters
❌ Omit explicit return types on functions
❌ Use type assertions without runtime validation
❌ Commit code with console.log statements
❌ Bypass strict mode checks
ALWAYS do these things:
✅ Define explicit types for all function parameters and return values
✅ Use type guards to narrow unknown types
✅ Use optional chaining (?.) and nullish coalescing (??)
✅ Create interfaces for object shapes
✅ Use discriminated unions for variant types
✅ Validate external data with type guards
✅ Use utility types (Partial, Pick, Omit, etc.) appropriately
✅ Write tests for all type guards and validation functions
This skill contains 9 comprehensive guides with 250+ code examples:
24 scenarios with before/after examples
any type (external APIs, event handlers, dynamic keys, array methods)@ts-ignore (third-party issues, complex casting)When to use: Before writing ANY TypeScript code, review this file for the specific pattern you need.
13 sections covering ALL React patterns
When to use: Writing ANY React component, hook, or pattern.
16 scenarios for untyped libraries
When to use: Integrating ANY third-party library without types.
15 categories of reusable type guards
When to use: Validating ANY external data or narrowing types.
12 advanced generic patterns
When to use: Creating ANY reusable function or data structure.
16 built-in utility types with decision trees
Decision trees included for choosing the right utility type.
When to use: Transforming ANY existing type.
13 async patterns
When to use: Writing ANY asynchronous code.
10 error handling patterns
When to use: Handling ANY errors or failures.
Executable Python script for pre-validation
Checks for:
any type usage@ts-ignore comments! non-null assertionsconsole.log in production codeRun before committing:
python .claude/skills/typescript-strict-guard/validate-types.py --dir src/
STEP 1: Identify the Pattern
Before writing code, ask:
STEP 2: Read the Relevant Section
Open the guide and find the exact pattern you need. Each guide has 20+ examples with before/after code.
STEP 3: Write Code Following the Pattern
Copy the pattern structure, adapt to your use case, ensure explicit types everywhere.
STEP 4: Validate
Run the validation script:
python .claude/skills/typescript-strict-guard/validate-types.py --file src/path/to/file.ts
STEP 5: Write Tests
Every type guard, validation function, and custom type needs tests.
STEP 1: Run Validation Script
python .claude/skills/typescript-strict-guard/validate-types.py --dir src/
STEP 2: Check for Common Violations
Consult Strict Mode Violations for the specific violation found.
STEP 3: Suggest Correct Pattern
Reference the appropriate guide section with the correct pattern.
STEP 4: Verify Tests Exist
All type guards and validation logic must have tests.
Is the data from external source (API, user input, JSON)?
├─ YES → Create type guard in [Type Guards Library](type-guards-library.md)
│ Example: isUser(data: unknown): data is User
│ Then: Validate before using
└─ NO → Can you define the type at compile time?
└─ YES → Use explicit type
└─ NO → Use unknown with type narrowing
What transformation do you need?
├─ Make properties optional → Partial<T>
├─ Make properties required → Required<T>
├─ Make properties readonly → Readonly<T>
├─ Select specific properties → Pick<T, K>
├─ Remove specific properties → Omit<T, K>
├─ Create object with keys → Record<K, T>
├─ Remove types from union → Exclude<T, U>
├─ Extract types from union → Extract<T, U>
├─ Remove null/undefined → NonNullable<T>
├─ Get function return type → ReturnType<T>
├─ Get function parameters → Parameters<T>
└─ Unwrap Promise → Awaited<T>
See: [Utility Types Guide](utility-types-guide.md)
What kind of error handling do you need?
├─ Explicit error as return value → Result<T, E> pattern
├─ Nullable value → Option<T> pattern
├─ Two distinct outcomes → Either<L, R> pattern
├─ Custom error with metadata → Extend ApplicationError class
├─ Multiple validation errors → ValidationResult<T> with errors array
├─ React component error → Error Boundary
└─ Async error handling → async Result<T, E>
See: [Error Handling Types](error-handling-types.md)
Scenario: Fetch user from API, validate data, handle errors, display in React component.
Step 1: Type Guard (Type Guards Library)
interface User {
id: string
name: string
email: string
}
function isUser(obj: unknown): obj is User {
return (
typeof obj === 'object' &&
obj !== null &&
'id' in obj && typeof obj.id === 'string' &&
'name' in obj && typeof obj.name === 'string' &&
'email' in obj && typeof obj.email === 'string'
)
}
Step 2: Async Function with Error Handling (Async Typing + Error Handling)
type Result<T, E = Error> =
| { success: true; data: T }
| { success: false; error: E }
async function fetchUser(id: string): Promise<Result<User>> {
try {
const response = await fetch(`/api/users/${id}`)
if (!response.ok) {
return {
success: false,
error: new Error(`HTTP ${response.status}`)
}
}
const data: unknown = await response.json()
if (!isUser(data)) {
return {
success: false,
error: new Error('Invalid user data from API')
}
}
return { success: true, data }
} catch (error) {
return {
success: false,
error: error instanceof Error ? error : new Error('Unknown error')
}
}
}
Step 3: React Component (React TypeScript Patterns)
interface UserProfileProps {
userId: string
}
function UserProfile({ userId }: UserProfileProps): React.ReactElement {
const [user, setUser] = useState<User | null>(null)
const [error, setError] = useState<string | null>(null)
const [loading, setLoading] = useState<boolean>(true)
useEffect(() => {
async function loadUser(): Promise<void> {
setLoading(true)
const result = await fetchUser(userId)
if (result.success) {
setUser(result.data)
setError(null)
} else {
setError(result.error.message)
setUser(null)
}
setLoading(false)
}
loadUser()
}, [userId])
if (loading) return <div>Loading...</div>
if (error) return <div>Error: {error}</div>
if (!user) return <div>User not found</div>
return (
<div>
<h1>{user.name}</h1>
<p>{user.email}</p>
</div>
)
}
Step 4: Tests
describe('fetchUser', () => {
it('should fetch user successfully', async () => {
const result = await fetchUser('1')
expect(result.success).toBe(true)
if (result.success) {
expect(result.data.id).toBe('1')
}
})
it('should handle invalid data', async () => {
// Mock returns invalid data
const result = await fetchUser('invalid')
expect(result.success).toBe(false)
if (!result.success) {
expect(result.error.message).toContain('Invalid user data')
}
})
})
describe('isUser', () => {
it('should validate correct user object', () => {
expect(isUser({ id: '1', name: 'Alice', email: '[email protected]' })).toBe(true)
})
it('should reject invalid object', () => {
expect(isUser({ id: 123 })).toBe(false)
expect(isUser(null)).toBe(false)
})
})
Step 5: Validate
python .claude/skills/typescript-strict-guard/validate-types.py --file src/components/UserProfile.tsx
✅ Result: Zero type errors, comprehensive error handling, full test coverage.
Before committing ANY TypeScript code:
# Validate all TypeScript files
python .claude/skills/typescript-strict-guard/validate-types.py --dir src/
# Run TypeScript compiler
npx tsc --noEmit
# Run tests
npm test
# Run linter
npm run lint
All checks must pass before code is committed.
| Violation | Quick Fix | Guide Section |
|-----------|-----------|---------------|
| any type | Use explicit type or unknown with type guard | Strict Mode Violations #1-4 |
| @ts-ignore | Fix underlying issue or create proper type | Strict Mode Violations #5-6 |
| ! assertion | Use ?. optional chaining or type guard | Strict Mode Violations #7-9 |
| Missing return type | Add : ReturnType to function | Strict Mode Violations #10-11 |
| Implicit any | Add type to parameters | Strict Mode Violations #12 |
| Untyped event | Use React.XEvent<HTMLElement> | React TypeScript Patterns #2 |
| External data | Create type guard | Type Guards Library #6 |
| Async error | Use Result<T, E> pattern | Error Handling Types #8 |
This skill is working when:
✅ Zero any types in production code
✅ Zero @ts-ignore comments
✅ Zero ! non-null assertions
✅ 100% explicit function return types
✅ All external data validated with type guards
✅ All type guards have tests
✅ TypeScript compiler passes with zero errors
✅ Validation script passes with zero violations
Always use when:
This skill prevents 99% of TypeScript errors before code is written.
Remember: TypeScript strict mode is not a burden - it's a superpower. Use this skill to write perfect TypeScript code the first time, every time.
development
Apple Human Interface Guidelines for content display components. Use this skill when the user asks about charts component, collection view, image view, web view, color well, image well, activity view, lockup, data visualization, content display, displaying images, rendering web content, color pickers, or presenting collections of items in Apple apps. Also use when the user says how should I display charts, what's the best way to show images, should I use a web view, how do I build a grid of items, what component shows media, or how do I present a share sheet. Cross-references: hig-foundations for color/typography/accessibility, hig-patterns for data visualization patterns, hig-components-layout for structural containers, hig-platforms for platform-specific component behavior.
tools
Automate HelpDesk tasks via Rube MCP (Composio): list tickets, manage views, use canned responses, and configure custom fields. Always search tools first for current schemas.
testing
Expert Haskell engineer specializing in advanced type systems, pure functional design, and high-reliability software. Use PROACTIVELY for type-level programming, concurrency, and architecture guidance.
tools
GraphQL gives clients exactly the data they need - no more, no less. One endpoint, typed schema, introspection. But the flexibility that makes it powerful also makes it dangerous. Without proper controls, clients can craft queries that bring down your server. This skill covers schema design, resolvers, DataLoader for N+1 prevention, federation for microservices, and client integration with Apollo/urql. Key insight: GraphQL is a contract. The schema is the API documentation. Design it carefully.