Avoid angle-bracket type assertions (<Type>) and use 'as Type' syntax instead
Replaces deprecated angle-bracket type assertions (<Type>) with modern 'as Type' syntax in TypeScript and TSX files. Triggered when encountering <Type>value patterns that cause JSX conflicts or syntax errors.
/plugin marketplace add djankies/claude-configs/plugin install typescript@claude-configsThis skill inherits all available tools. When active, it can use any tool Claude has access to.
The angle-bracket type assertion syntax (<Type>value) is deprecated in TypeScript, especially in TSX files where it conflicts with JSX syntax.
<Type> Syntaxas Typeas TypeDeprecated:
const value = <string>someValue;
const num = <number>input;
Modern:
const value = someValue as string;
const num = input as number;
Deprecated:
const user = <User>jsonData;
const config = <AppConfig>settings;
Modern:
const user = jsonData as User;
const config = settings as AppConfig;
Type assertions bypass type checking and should be avoided when possible.
Bad:
function processValue(value: unknown) {
const str = value as string;
return str.toUpperCase();
}
Good:
function processValue(value: unknown) {
if (typeof value === 'string') {
return value.toUpperCase();
}
throw new Error('Expected string');
}
Bad:
const user = apiResponse as User;
Good:
function isUser(value: unknown): value is User {
return (
typeof value === 'object' &&
value !== null &&
'id' in value &&
'name' in value &&
typeof value.id === 'number' &&
typeof value.name === 'string'
);
}
const parsed = apiResponse;
if (isUser(parsed)) {
const user = parsed;
} else {
throw new Error('Invalid user data');
}
Best:
import { z } from 'zod';
const UserSchema = z.object({
id: z.number(),
name: z.string(),
email: z.string().email(),
});
type User = z.infer<typeof UserSchema>;
const user = UserSchema.parse(apiResponse);
Bad:
const element = document.getElementById('myId') as HTMLButtonElement;
Better:
const element = document.getElementById('myId');
if (element instanceof HTMLButtonElement) {
element.addEventListener('click', handler);
}
Or use querySelector with type inference:
const element = document.querySelector<HTMLButtonElement>('#myId');
if (element) {
element.addEventListener('click', handler);
}
Bad:
function handleEvent(event: Event) {
const mouseEvent = event as MouseEvent;
console.log(mouseEvent.clientX);
}
Good:
type AppEvent =
| { type: 'mouse'; clientX: number; clientY: number }
| { type: 'keyboard'; key: string }
| { type: 'custom'; data: unknown };
function handleEvent(event: AppEvent) {
switch (event.type) {
case 'mouse':
console.log(event.clientX);
break;
case 'keyboard':
console.log(event.key);
break;
case 'custom':
console.log(event.data);
break;
}
}
In TSX files, angle-bracket syntax causes syntax errors:
Will cause syntax error in TSX:
const Component = () => {
const value = <string>getData();
return <div>{value}</div>;
};
Must use as syntax:
const Component = () => {
const value = getData() as string;
return <div>{value}</div>;
};
Even better - validate properly:
const Component = () => {
const data = getData();
if (typeof data !== 'string') {
throw new Error('Expected string');
}
return <div>{data}</div>;
};
If you must use assertions (rare cases):
as const for Literal Typesconst config = {
apiUrl: 'https://api.example.com',
timeout: 5000,
} as const;
as Type (Never <Type>)const value = unknownValue as SomeType;
const element = document.getElementById('app-root') as HTMLDivElement;
Find all angle-bracket assertions:
grep -r '<[A-Z][a-zA-Z]*>' --include="*.ts" --include="*.tsx"
Replace with as syntax:
<Type>value → value as TypeReview each assertion:
Enable linting:
{
"rules": {
"@typescript-eslint/consistent-type-assertions": [
"error",
{
"assertionStyle": "as",
"objectLiteralTypeAssertions": "never"
}
]
}
}
Enforce as syntax and discourage assertions:
{
"rules": {
"@typescript-eslint/consistent-type-assertions": [
"error",
{
"assertionStyle": "as",
"objectLiteralTypeAssertions": "never"
}
],
"@typescript-eslint/no-unnecessary-type-assertion": "error"
}
}
Never use angle-bracket syntax:
as Type when assertions are unavoidableThis skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
This skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.
This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.