SShortSingh.
Back to feed

Why TypeScript Developers Should Replace try-catch with Functional Either Types

0
·1 views

TypeScript's exception-based error handling hides failures from function signatures, leaving callers unaware that a function can throw and forcing them to rely on try-catch blocks without compiler support. A functional alternative called the Either type explicitly encodes success or failure in the return type, making error states visible and compiler-enforced. Using Either, a function returns either a Right value on success or a Left value containing a typed error, eliminating guesswork in catch blocks. Operations can be composed cleanly using pipe and chain utilities, where any failing step short-circuits the pipeline and propagates the error automatically with its type intact. This approach improves code reliability and readability by ensuring error handling is explicit, typed, and impossible to accidentally overlook.

Read the full story at DEV Community

This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)

Log in to join the discussion and vote.

Log in

Related stories

0
ProgrammingDEV Community ·

Nearly Half of Top News Sites Now Block OpenAI's Crawler, Reuters Institute Finds

Major news publishers are increasingly restricting AI web crawlers, with a Reuters Institute study finding that about 48% of the world's top online news sites had blocked OpenAI's GPTBot by end of 2023. The response was sharpest in the United States, where roughly 79% of leading news sites blocked OpenAI's crawler, compared to only 24% blocking Google's AI crawler globally. Publishers are concerned that their reporting may be used to train AI models or generate answers without proper compensation, attribution, or referral traffic. High-profile actions include The Guardian blocking GPTBot in September 2023 and The New York Times suing OpenAI and Microsoft in December 2023 over alleged misuse of its content. While some publishers opt for outright blocking, others like Axel Springer have pursued licensing deals, reflecting an evolving and unsettled commercial landscape for AI access to journalism.

0
ProgrammingDEV Community ·

Apple Sign-In Breaks Every 6 Months Due to Expiring JWT Client Secret

Developers using Sign in with Apple on the web may find authentication suddenly failing with an 'invalid_client' error approximately six months after setup, caused by Apple's mandatory expiry limit on JWT client secrets. Unlike other OAuth providers such as Google or GitHub, Apple requires developers to manually generate a time-limited JWT signed with a private .p8 key, which expires after a maximum of roughly 15.7 million seconds. Apple sends no warning when the secret expires, meaning users typically encounter the failure before developers do. The standard fix involves generating a fresh JWT and updating it in the authentication provider's dashboard, but this must be repeated every six months. To automate the process, a GitHub Action called apple-client-secret-rotator has been released, which regenerates and updates the secret on a scheduled basis, eliminating the need for manual intervention.

0
ProgrammingDEV Community ·

Build Only What Differentiates Your MVP, Rent Everything Else

When scoping a minimum viable product, founders face a critical early decision: what to build themselves and what to purchase as a service. The core principle is that only the unique, differentiating feature of a product warrants custom development, while common infrastructure like authentication, payments, and email should be rented from specialist providers. Building commodity capabilities in-house wastes time that could be spent on the actual value proposition, and specialist vendors bring security, compliance, and reliability that small teams cannot replicate. However, renting carries its own risks — vendor lock-in, price changes, and API instability — so dependencies should be isolated behind internal interfaces to limit exposure. The most dangerous trap is mistaking a capability that sits adjacent to the core differentiator for part of it, leading teams to over-build where off-the-shelf solutions already exist.

Why TypeScript Developers Should Replace try-catch with Functional Either Types · ShortSingh