Library Socialism
  • Communities
  • Create Post
  • Create Community
  • heart
    Support Lemmy
  • search
    Search
  • Login
  • Sign Up
洪 民憙 (Hong Minhee)@lemmy.ml to TypeScript@lemmy.mlEnglish · 10 months ago

Designing type-safe sync/async mode support in TypeScript

hackers.pub

external-link
message-square
0
link
fedilink
  • cross-posted to:
  • typescript@programming.dev
1
external-link

Designing type-safe sync/async mode support in TypeScript

hackers.pub

洪 民憙 (Hong Minhee)@lemmy.ml to TypeScript@lemmy.mlEnglish · 10 months ago
message-square
0
link
fedilink
  • cross-posted to:
  • typescript@programming.dev
Optique, a type-safe CLI parser for TypeScript inspired by functional programming principles, recently introduced support for both synchronous and asynchronous execution modes to handle complex requirements like dynamic shell completions. Implementing this feature required sophisticated type-level logic to ensure that combining an asynchronous parser with synchronous ones correctly results in an asynchronous aggregate. After evaluating several design patterns, the developer settled on an explicit mode parameter with a default value to maintain backward compatibility while allowing for runtime inspection. This approach leverages conditional types and advanced inference to compute combined modes automatically, even though it necessitated significantly increasing internal implementation complexity to support dual execution paths. The updated API now includes specialized runners that provide compile-time enforcement of the expected execution mode, preventing common pitfalls associated with asynchronous code. By prioritizing a clean user-facing interface, the library successfully integrates asynchronous capabilities without compromising its original simplicity or type safety. This architectural evolution demonstrates how TypeScript’s powerful type system can manage complex state propagation while keeping the development experience intuitive and robust.
alert-triangle
You must log in or register to comment.

TypeScript@lemmy.ml

typescript@lemmy.ml

Subscribe from Remote Instance

Create a post
You are not logged in. However you can subscribe from another Fediverse account, for example Lemmy or Mastodon. To do this, paste the following into the search field of your instance: !typescript@lemmy.ml

TypeScript is a language for application-scale JavaScript development. TypeScript is a typed superset of JavaScript that compiles to plain JavaScript.

Visibility: Public
globe

This community can be federated to other instances and be posted/commented in by their users.

  • 5 users / day
  • 5 users / week
  • 5 users / month
  • 5 users / 6 months
  • 1 local subscriber
  • 244 subscribers
  • 27 Posts
  • 0 Comments
  • Modlog
  • mods:
  • dinomug@lemmy.ml
  • BE: 0.19.20
  • Modlog
  • Instances
  • Docs
  • Code
  • join-lemmy.org