🎯

write-modern-javascript

🎯Skill

from marius-townhouse/effective-typescript-skills

VibeIndex|
What it does

Generates modern, efficient JavaScript by leveraging TypeScript's compilation and downleveling capabilities for optimal browser compatibility and bundle size.

πŸ“¦

Part of

marius-townhouse/effective-typescript-skills(83 items)

write-modern-javascript

Installation

Quick InstallInstall with npx
npx skills add marius-townhouse/effective-typescript-skills --all
Quick InstallInstall with npx
npx skills add marius-townhouse/effective-typescript-skills -s prefer-unknown-over-any exhaustiveness-checking
Quick InstallInstall with npx
npx skills add marius-townhouse/effective-typescript-skills -a opencode claude-code
Quick InstallInstall with npx
npx skills add marius-townhouse/effective-typescript-skills -l
git cloneClone repository
git clone https://github.com/marius-townhouse/effective-typescript-skills.git
πŸ“– Extracted from docs: marius-townhouse/effective-typescript-skills
1Installs
-
AddedFeb 4, 2026

Skill Details

SKILL.md

Use when writing TypeScript that compiles to JavaScript. Use when configuring tsconfig target. Use when choosing language features. Use when supporting older browsers. Use when optimizing bundle size.

Overview

# Write Modern JavaScript

Overview

TypeScript compiles to JavaScript, and the quality of that output depends on your target configuration and coding style. Write modern JavaScript (ES2020+) and let TypeScript handle compatibility through downleveling. Modern features often produce cleaner, more efficient code than manually implementing fallbacks.

Avoid TypeScript features that compile to verbose JavaScript when standard modern features exist.

When to Use This Skill

  • Writing TypeScript that compiles to JavaScript
  • Configuring tsconfig.json target
  • Choosing which language features to use
  • Supporting older browsers through compilation
  • Optimizing bundle size

The Iron Rule

Write modern JavaScript (ES2020+) and let TypeScript downlevel for older environments. Prefer standard features over TypeScript-specific ones that compile to verbose code.

Detection

Watch for outdated patterns:

```typescript

// RED FLAGS - Outdated patterns

var x = 1; // Use const/let

function Person() { } // Use class

Promise.resolve().then(...); // Use async/await

Object.assign({}, obj); // Use spread: { ...obj }

```

Modern Features to Prefer

```typescript

// Use const/let instead of var

const PI = 3.14159;

let count = 0;

// Use arrow functions for callbacks

const doubled = numbers.map(n => n * 2);

// Use destructuring

const { name, age } = person;

const [first, ...rest] = items;

// Use spread instead of Object.assign

const merged = { ...defaults, ...options };

const combined = [...arr1, ...arr2];

// Use async/await instead of Promise chains

async function fetchData() {

const response = await fetch('/api/data');

const data = await response.json();

return data;

}

// Use optional chaining

const street = user?.address?.street;

// Use nullish coalescing

const value = input ?? 'default';

```

Configure Target Appropriately

```json

// tsconfig.json

{

"compilerOptions": {

"target": "ES2020", // Modern target for modern output

"lib": ["ES2020", "DOM"], // Include modern APIs

"module": "ESNext", // Use ES modules

"moduleResolution": "node"

}

}

```

Let TypeScript Handle Compatibility

```typescript

// Write modern code:

class Person {

name: string;

#age: number; // Private field

constructor(name: string, age: number) {

this.name = name;

this.#age = age;

}

async celebrate() {

return ${this.name} is ${this.#age}!;

}

}

// TypeScript compiles for target: ES2015

// or passes through for target: ES2022

```

Avoid Verbose TypeScript Patterns

```typescript

// AVOID: TypeScript parameter properties

class Point {

constructor(public x: number, public y: number) {}

}

// Compiles to verbose code with assignments

// PREFER: Standard class fields (ES2022+)

class Point {

x: number;

y: number;

constructor(x: number, y: number) {

this.x = x;

this.y = y;

}

}

// Cleaner output, standard JavaScript

```

Pressure Resistance Protocol

When writing TypeScript:

  1. Use latest target: Set target to ES2020 or later
  2. Write modern JS: Use current JavaScript features
  3. Let TS handle compatibility: Trust the compiler
  4. Review output: Check compiled code occasionally
  5. Avoid TS-only features: Unless necessary

Red Flags

| Anti-Pattern | Problem | Solution |

|--------------|---------|----------|

| var declarations | Outdated, scoping issues | Use const/let |

| Manual Promise chains | Harder to read | Use async/await |

| Object.assign | Verbose | Use spread operator |

| Array.prototype methods | Verbose | Use modern array methods |

Common Rationalizations

"I need to support old browsers"

Reality: Configure target appropriately and let TypeScript downlevel. Don't write outdated code manually.

"I'm used to the old way"

Reality: Modern JavaScript is cleaner and more maintainable. Take time to learn current patterns.

"It compiles to the same thing"

Reality: Often it doesn't. Modern features can produce more efficient code.

Quick Reference

| Instead Of | Use | Benefit |

|------------|-----|---------|

| var | const/let | Block scope, no hoisting issues |

| function callbacks | Arrow functions | Lexical this, cleaner |

| .then() chains | async/await | Readable, easier error handling |

| Object.assign() | Spread {...obj} | Cleaner, standard |

| arr.indexOf() !== -1 | arr.includes() | Clearer intent |

| Manual loops | map, filter, reduce | Declarative, functional |

The Bottom Line

Write modern JavaScript and let TypeScript handle compatibility. Modern features produce cleaner code and TypeScript's downleveling ensures it works where needed.

Reference

  • Effective TypeScript, 2nd Edition by Dan Vanderkam
  • Item 79: Write Modern JavaScript

More from this repository10

🎯
tsdoc-comments🎯Skill

Generates TypeScript documentation comments (TSDoc) to explain public APIs, complex types, and provide comprehensive code documentation with IDE tooltips.

🎯
async-over-callbacks🎯Skill

Transforms callback-based asynchronous code into clean, readable async/await patterns for better type flow and error handling.

🎯
type-safe-monkey-patching🎯Skill

Enables type-safe runtime extension of global objects and DOM elements in TypeScript without sacrificing type checking or using `as any`.

🎯
create-objects-all-at-once🎯Skill

Efficiently initializes multiple TypeScript objects simultaneously using concise object literal syntax and spread operators.

🎯
module-by-module-migration🎯Skill

Guides developers through systematic TypeScript module migration, breaking down complex refactoring into manageable, incremental steps.

🎯
ts-js-relationship🎯Skill

Explains TypeScript's relationship to JavaScript, highlighting how it adds static typing and catches errors before runtime while remaining fully compatible with JavaScript code.

🎯
code-gen-independent🎯Skill

Generates JavaScript code despite TypeScript type errors and demonstrates that TypeScript types are erased at runtime, requiring alternative type checking strategies.

🎯
context-type-inference🎯Skill

Helps restore precise type context when extracting values, preventing type inference errors through annotations, const assertions, and type preservation techniques.

🎯
precise-string-types🎯Skill

Enforces strict string type constraints and prevents unintended string type conversions in TypeScript projects.

🎯
type-display-attention🎯Skill

Displays and simplifies complex TypeScript types to improve IDE readability and developer experience.