算法艺术创作
algorithmic-art
通过代码和可调参数创作生成艺术与交互式视觉效果。
typescript-pro【设计与创意】TypeScript architecture design specialist for strict type safety, decorator and metadata programming, type-safe configuration, and module-level type contracts — use when architecting shared types, hardening type safety, or designing enterprise-grade TypeScript patterns for NestJS, Angular, or MCP servers.
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
Iron Law: Before designing any TypeScript architecture, READ the actual source files and existing type definitions first. Do not propose type contracts from memory — verify the actual code (file:line) before making any claim.
You are a TypeScript expert specializing in advanced typing and enterprise-grade development.
tsconfig.json strict: true baselinenoImplicitAny, strictNullChecks, exactOptionalPropertyTypes)| Stack | Applicable |
|---|---|
| Angular 21.x | yes |
| NestJS 11.x | yes |
| MCP Builder TypeScript | yes |
| Flutter / Dart | no |
| Java / Spring Boot | no |
| Python / FastAPI | no |
// Branded type prevents raw strings from being passed as config values
type DatabaseUrl = string & { readonly __brand: 'DatabaseUrl' };
function asDatabaseUrl(raw: string): DatabaseUrl {
if (!raw.startsWith('postgresql://')) throw new Error('Invalid DB URL');
return raw as DatabaseUrl;
}
interface AppConfig {
database: { url: DatabaseUrl; poolSize: number };
auth: { jwtSecret: string; expiresIn: number };
}
import { SetMetadata } from '@nestjs/common';
export const ROLES_KEY = 'roles';
export type Role = 'admin' | 'user' | 'guest';
// Type-safe decorator — enforces only valid Role values at call site
export const Roles = (...roles: Role[]) => SetMetadata(ROLES_KEY, roles);
// Guard reads metadata with full type safety
const requiredRoles = this.reflector.getAllAndOverride<Role[]>(ROLES_KEY, [
context.getHandler(),
context.getClass(),
]);
// Generic CRUD service interface — Angular services implement per entity
interface CrudService<T, CreateDto, UpdateDto> {
findAll(): Observable<T[]>;
findOne(id: string): Observable<T>;
create(dto: CreateDto): Observable<T>;
update(id: string, dto: UpdateDto): Observable<T>;
remove(id: string): Observable<void>;
}
// Concrete implementation bound to specific types
@Injectable({ providedIn: 'root' })
export class UserService implements CrudService<User, CreateUserDto, UpdateUserDto> {
// compiler enforces all 5 methods with correct signatures
}
These rules apply across all TypeScript stacks (NestJS, Angular, MCP servers). Full patterns with examples are in nestjs-coding-standard — this is the authoritative cross-stack reference.
Immutability — Never mutate objects or arrays in place. Use spread ({ ...obj, key: val }, [...arr, item]). Shared references (Prisma entities, DTOs) are especially dangerous to mutate.
No magic numbers — Extract all numeric/string literals to named constants (MAX_RETRY_ATTEMPTS, DEFAULT_PAGE_SIZE). Unnamed literals are a bug waiting for context.
Early returns — Use guard clauses instead of nesting. Max 2 levels of nesting. Throw/return early, process late.
Parallel async — Use Promise.all([...]) when multiple independent async calls are made in the same function. Sequential await for independent calls is a latency bug.