Skip to content
Back to skills

1859 Maintainability Type Hints 68325d89

ASecurity

Use type annotations to make code self-documenting and catch errors early.

  • 9 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added June 1, 2026
code-qualitytypescriptpythongorefactoringdocumentation

Security analysis

A100/100

Pro scans all 2 files and shows the line behind each finding

Scanned June 1, 2026

npx -y skills add tools-only/X-Skills --skill 1859-maintainability-type-hints_68325d89 --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of 1859 Maintainability Type Hints 68325d89?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for 1859 Maintainability Type Hints 68325d89
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/tools-only-1859-maintainability-type-hints-68325d89/badge)](https://www.skillsdirectory.com/skills/tools-only-1859-maintainability-type-hints-68325d89)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
title: Add Type Hints
impact: MEDIUM
category: maintainability
tags: types, python, typescript, type-safety
---

# Add Type Hints

Use type annotations to make code self-documenting and catch errors early.

## Why This Matters

Type hints provide:
- **Static analysis** - catch bugs before runtime
- **Better IDE support** - autocomplete, refactoring
- **Documentation** - types explain intent
- **Confidence** - easier refactoring

##❌ Incorrect

```python
# ❌ No type hints
def get_user(id):
    return users.get(id)

def process_order(order, discount):
    if discount:
        return order['total'] * (1 - discount)
    return order['total']
```

## ✅ Correct

```python
# ✅ Full type hints
from typing import Optional, Dict, Any

def get_user(id: int) -> Optional[Dict[str, Any]]:
    """Fetch user by ID.
    
    Args:
        id: User ID
        
    Returns:
        User dict or None if not found
    """
    return users.get(id)

def process_order(order: Dict[str, Any], discount: Optional[float] = None) -> float:
    """Calculate order total with optional discount.
    
    Args:
        order: Order dictionary with 'total' key
        discount: Discount rate (0.0-1.0), e.g. 0.1 for 10% off
        
    Returns:
        Final price after discount
    """
    if discount:
        return order['total'] * (1 - discount)
    return order['total']
```

## TypeScript

```typescript
// ✅ Explicit types
interface User {
  id: number;
  name: string;
  email: string;
}

function getUser(id: number): User | null {
  return users.get(id) ?? null;
}

function processOrder(
  order: { total: number },
  discount?: number
): number {
  if (discount) {
    return order.total * (1 - discount);
  }
  return order.total;
}
```

## References

- [Python Type Hints](https://docs.python.org/3/library/typing.html)
- [TypeScript Handbook](https://www.typescriptlang.org/docs/handbook/intro.html)

Files in this skill

  • README.md993 B
  • skill.md1.9 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.