typescript
This directory provides Talon voice command support and code automation specifically tailored for TypeScript and TypeScript React (.tsx) development. It builds upon general JavaScript capabilities by layering in TypeScript-specific language features like static types, access modifiers (public/private/protected), type assertions, and type aliases.
The implementation consists of two main files:
- typescript.py – Sets up the programming context, handles type-related lists, and overrides actions for formatting object-oriented structures.
- typescript.talon – Defines the voice commands that trigger TypeScript syntax structures.
Context and Action Overrides
The typescript.py file activates when the active language is typescript or typescriptreact. It specifies a higher priority (via mode: command) to ensure TypeScript behaviors win over standard JavaScript overrides when editing TypeScript files.
It manages several key responsibilities:
- Type Definitions List: It populates the
user.code_typelist with primitive TypeScript types (such asboolean,string,number,any, etc.), allowing you to voice-insert specific types on the fly. - Access Modifier Functions: It overrides default user actions to support formatting for typescript functions with access modifiers:
code_private_function: Inserts aprivate function <name>signature.code_protected_function: Inserts aprotected function <name>signature.code_public_function: Inserts apublic function <name>signature.
- Type Annotations: Implements actions to inject type annotations (
: <type>) for variables and return types.
Voice Commands
The typescript.talon file maps natural voice commands to TypeScript syntax mechanisms.
The file defines several essential syntax shortcuts:
- Union and Intersection Types:
- Saying
"type union [type]"yields| <type>(e.g.,| string). - Saying
"type intersect [type]"yields& <type>.
- Saying
- Type Aliases: Saying
"state type"types out a type declaration stub:type =and positions the cursor between the space and the equals sign using theuser.insert_betweenaction. - Const Assertions: Saying
"as const"appendsas const, which is commonly used to lock down literal types in TypeScript.