This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // analytics.d.ts - correct approach | |
| declare namespace Analytics { | |
| interface Config { | |
| apiKey: string; | |
| endpoint: string; | |
| } | |
| function track(event: string, properties?: Record<string, unknown>): void; | |
| function identify(userId: string, traits?: Record<string, unknown>): void; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // enhanced-websocket.d.ts | |
| declare namespace EnhancedWS { | |
| interface ConnectionOptions { | |
| reconnect: boolean; | |
| maxRetries: number; | |
| timeout: number; | |
| } | |
| interface Message<T = unknown> { | |
| type: string; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // dom-extensions.d.ts | |
| declare namespace NodeJS { | |
| interface ProcessEnv { | |
| NEXT_PUBLIC_API_URL: string; | |
| NEXT_PUBLIC_FEATURE_FLAG: string; | |
| } | |
| } | |
| declare interface Window { | |
| gtag: ( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // express-augmentation.d.ts | |
| import "express"; | |
| declare module "express" { | |
| namespace Express { | |
| interface Request { | |
| user?: { | |
| id: string; | |
| email: string; | |
| roles: string[]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // winston-augmentation.d.ts | |
| import "winston"; | |
| declare module "winston" { | |
| namespace winston { | |
| interface LoggerOptions { | |
| datadogApiKey?: string; | |
| datadogService?: string; | |
| enableCloudWatch?: boolean; | |
| cloudWatchGroup?: string; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // legacy-validators.ts | |
| namespace DataValidation { | |
| export namespace Email { | |
| export function isValid(email: string): boolean { | |
| return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email); | |
| } | |
| export function normalize(email: string): string { | |
| return email.toLowerCase().trim(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // validators/email.ts | |
| export function isValid(email: string): boolean { | |
| return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email); | |
| } | |
| export function normalize(email: string): string { | |
| return email.toLowerCase().trim(); | |
| } | |
| // validators/phone.ts |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // broken-mixed-pattern.ts - DO NOT DO THIS | |
| import { logger } from "./logger"; | |
| namespace Utils { | |
| export function logError(message: string): void { | |
| // logger is undefined here at runtime | |
| logger.error(message); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // fixed-module-pattern.ts | |
| import { logger } from "./logger"; | |
| export function logError(message: string): void { | |
| logger.error(message); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| interface Timestamped { | |
| timestamp: number; | |
| } | |
| function logWithTime<T extends Timestamped>(item: T): void { | |
| console.log(`[${new Date(item.timestamp).toISOString()}]`, item); | |
| } | |
| // Valid: object satisfies constraint | |
| logWithTime({ timestamp: Date.now(), message: "Event" }); |
NewerOlder