JavaScript · Promises · Tech Lead · Architecture
You lead multiple teams shipping JS SDKs. What standards would you set for Promise-based APIs?
Short Interview Answer
Always return promises (no mixed callback-required APIs), never throw sync after starting async, document rejection types, support AbortSignal, and avoid deferred anti-patterns.
Detailed Explanation
Conventions: functions return Promise; use async/await internally; reject with Error subclasses (typed codes); do not sometimes return values and sometimes promises; support cancellation via `signal`; provide timeouts as options; no floating promises in examples; expose `using`/disposables where resources need cleanup. Ban promise constructor anti-pattern in reviews. Provide dual error strategies carefully (Result vs throw) but pick one per layer. Versioning: changing rejection shapes is a breaking change. Add lint rules for floating promises in TS (`no-floating-promises`). Align logging of unhandledrejections in apps consuming the SDK.
Interview Tip
Emphasize consistency across teams — leadership lens.
Common Mistake
SDKs that accept callbacks optionally and return inconsistent types.