language-typescriptlisted
Install: claude install-skill lugassawan/swe-workbench
# TypeScript / JavaScript
## Strict mode or nothing
Enable in `tsconfig.json`:
```json
{
"compilerOptions": {
"strict": true,
"noUncheckedIndexedAccess": true,
"noImplicitOverride": true,
"exactOptionalPropertyTypes": true
}
}
```
Without these, types lie.
## Prefer `unknown` over `any`
`any` turns off the type system. `unknown` forces narrowing.
```ts
function parse(input: unknown): User {
if (!isUser(input)) throw new Error("invalid user");
return input;
}
```
## Discriminated unions over enums
Enums have runtime quirks and poor exhaustiveness. Use string-literal unions with a discriminant.
```ts
type Event =
| { kind: "click"; x: number; y: number }
| { kind: "submit"; form: FormData };
function handle(e: Event) {
switch (e.kind) {
case "click": return trackClick(e.x, e.y);
case "submit": return submit(e.form);
default: {
const _exhaustive: never = e; return _exhaustive;
}
}
}
```
## Branded types for domain primitives
Stop `UserId` from being passed where an `OrderId` is expected.
```ts
type Brand<K, T> = K & { readonly __brand: T };
type UserId = Brand<string, "UserId">;
type OrderId = Brand<string, "OrderId">;
const makeUserId = (s: string): UserId => s as UserId;
```
## Async patterns
- `await` everything that returns a promise. Floating promises silently swallow errors.
- Enable `@typescript-eslint/no-floating-promises`.
- `Promise.all` for all-or-fail; `Promise.allSettled` when partial failure is accep