djankies/claude-configs/avoiding-angle-bracket-assertions
Claude Code and agent skill by djankies/claude-configs
- community
Checking that the SKILL.md file is still in the repository.
Avoid angle-bracket type assertions (<Type>) and use 'as Type' syntax instead
Install
npx vskill@latest install djankies/claude-configs/avoiding-angle-bracket-assertionsSKILL.md
The same SKILL.md was published earlier as djankies/claude-configs/avoiding-angle-bracket-assertions.
Avoiding Angle-Bracket Type Assertions
The angle-bracket type assertion syntax (<Type>value) is deprecated in TypeScript, especially in TSX files where it conflicts with JSX syntax.
Why Avoid <Type> Syntax
- JSX conflict: Incompatible with TSX files (React, Preact, etc.)
- Inconsistent syntax: Modern TypeScript uses
as Type - Reduced readability: Looks like generics or JSX
- Tooling issues: Some tools don't handle it well
Modern Alternative: as Type
Basic Replacement
Deprecated:
Modern:
With Complex Types
Deprecated:
Modern:
Better: Avoid Type Assertions Entirely
Type assertions bypass type checking and should be avoided when possible.
1. Use Type Guards Instead
Bad:
Good:
2. Use Validation Functions
Bad:
Good:
3. Use Validation Libraries
Best:
4. Improve Type Inference
Bad:
Better:
Or use querySelector with type inference:
5. Use Discriminated Unions
Bad:
Good:
TSX-Specific Issues
In TSX files, angle-bracket syntax causes syntax errors:
Will cause syntax error in TSX:
Must use `as` syntax:
Even better - validate properly:
When Assertions Are Necessary
If you must use assertions (rare cases):
1. Use as const for Literal Types
2. Use as Type (Never <Type>)
3. Document Why It's Safe
Migration Strategy
- Find all angle-bracket assertions:
``bash grep -r '<[A-Z][a-zA-Z]*>' --include="*.ts" --include="*.tsx" ``
- Replace with `as` syntax:
<Type>value→value as Type
- Review each assertion:
- Can it be replaced with a type guard?
- Can validation library be used?
- Is it truly necessary?
- Enable linting:
``json { "rules": { "@typescript-eslint/consistent-type-assertions": [ "error", { "assertionStyle": "as", "objectLiteralTypeAssertions": "never" } ] } } ``
ESLint Configuration
Enforce as syntax and discourage assertions:
Summary
Never use angle-bracket syntax:
- Use
as Typewhen assertions are unavoidable - Prefer type guards over assertions
- Use validation libraries for external data
- Validate at runtime for safety
- Document why assertions are necessary
- Enable linting to enforce consistency
Security
- Security scanPassed, 90 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingtypescript/skills/avoiding-angle-bracket-assertions/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/djankies/claude-configs/avoiding-angle-bracket-assertions)