consistent-aliases

Enforce consistent alias usage to preserve TypeScript narrowing across scopes.

Updated Jul 17, 2017
One-click install
npx skills add https://github.com/luyi985/lyi-bash --skill consistent-aliases
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: consistent-aliases
Source: https://github.com/luyi985/lyi-bash/tree/main/ai/skills/consistent-aliases
Command: npx skills add https://github.com/luyi985/lyi-bash --skill consistent-aliases

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Narrowing rules in TypeScript can break when developers create local aliases from object properties or switch between alias and original names. This Skill provides guidance to maintain consistent aliasing so refinements remain reliable across a code path.

Core Features & Use Cases

  • Enforces a single aliasing approach per scope to prevent misleading type refinements.
  • Recommends destructuring and local variables to stabilize narrowing across function calls.
  • Includes practical patterns for safe readonly usage to protect existing refinements.

Quick Start

Destructure from objects and prefer a single, consistently named alias within each scope to keep type refinements stable.

Frequently Asked Questions about consistent-aliases

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
Why does TypeScript narrowing break after assigning an object property to a local variable?

TypeScript narrowing breaks after aliasing because the compiler loses track of refinements when switching between an original object property and a newly assigned local variable, making the narrowed type unreliable across the code path.

How do I preserve TypeScript narrowing after destructuring an object?

To preserve TypeScript narrowing after destructuring, enforce a single consistent aliasing approach per scope and prefer using destructured local variables exclusively to stabilize type refinements across subsequent function calls.

What are the best practices for safe readonly usage to maintain type refinements in TypeScript?

Best practices for safe readonly usage involve applying practical aliasing patterns that isolate refinements, ensuring that readonly properties are consistently aliased to protect existing type refinements from being lost during code execution.

Can I use destructuring to fix unreliable type narrowing across function calls in TypeScript?

Yes, you can use destructuring to fix unreliable type narrowing across function calls by extracting object properties into consistently named local variables, which isolates refinements and prevents the compiler from discarding narrowed types.

When should I avoid switching between an alias and the original object name in TypeScript?

You should avoid switching between an alias and the original object name whenever a scope requires reliable type narrowing, as inconsistent aliasing misleads the compiler and causes it to discard established refinements unexpectedly.