SShortSingh.
Back to feed

TypeScript's Strict Null Checks Won't Save You From Runtime Crashes

0
·1 views

A developer discovered that enabling strict null checks in TypeScript is not enough to prevent null-related runtime errors, even when code compiles cleanly without warnings. The core issue is that the TypeScript compiler validates static types but cannot verify the actual shape of data arriving from external sources like APIs, databases, or HTTP headers. Two specific failure patterns are highlighted: assertion functions that log warnings instead of throwing errors, causing TypeScript to trust a false type contract, and third-party library type definitions that do not accurately reflect real runtime return values. The article uses a Next.js and Prisma ORM stack as a practical reference to illustrate where the compiler silently approves code that later fails in production. The author argues that true null safety requires runtime validation at system boundaries, treating the compiler as only the first layer of defense.

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 ·

Masked Call Routing: A Privacy-Safe Fix for Blocking Cars in Indian Cities

A common urban problem in Indian cities — strangers needing to contact a car owner blocking a driveway or gate — doubles as a compelling systems design challenge. The traditional solution of displaying a phone number on a windshield sticker exposes the owner's personal number permanently to anyone who sees it, including marketers and bad actors. A more robust approach uses masked call routing, similar to systems used by cab and delivery apps, where scanning a QR code on the vehicle triggers a server-side binding between a temporary virtual number and the owner's real number. The virtual number is leased for a short window, typically around ten minutes, after which the binding is torn down and the number returned to a shared pool. Key design considerations include correct pool sizing based on peak concurrency, strict one-to-one number bindings to prevent misdirected calls, and safeguards against potential harassment since the system effectively allows any stranger to make an owner's phone ring.

0
ProgrammingDEV Community ·

Vue 3 and pdf-lib Enable Fully Browser-Based PDF Watermarking Tool

A developer has detailed how to build a browser-based PDF watermarking tool using Vue 3, pdf-lib, and PDF.js, processing files entirely on the user's device without server uploads. The approach addresses privacy concerns associated with traditional watermark tools that send potentially sensitive documents to remote servers. The implementation covers text rendering, rotation correction, and multi-page support, including a mathematical fix to center rotated text accurately on each page. Configurable options such as font size, opacity, rotation angle, color, and page range are supported to suit different use cases. The full source code is available on GitHub, and the post notes that image-based watermarks using PNG logos would require a separate approach beyond pdf-lib's built-in text drawing methods.

0
ProgrammingDEV Community ·

Developer Launches Free Open-Source Invoice Generator Requiring No Sign-Up

A developer named Vlad has released EasyInvoicePDF, a free and open-source tool for generating professional invoices. The project was created out of frustration with costly and overly complex invoicing software. The tool offers features including live PDF preview, instant download, customizable templates, and support for over 120 currencies and multiple languages. Users can save seller and buyer profiles and apply flexible tax options such as VAT and sales tax. The source code is publicly available on GitHub and the developer is actively welcoming feedback and feature suggestions.

0
ProgrammingDEV Community ·

How to Resolve 'Duplicate Class' Android Build Errors in React Native and Expo

React Native and Expo developers frequently encounter a 'Duplicate class' Gradle build error on Android, typically triggered after installing a new package, upgrading Expo, or changing a dependency. The error occurs when two different libraries include the same compiled Java or Kotlin class, causing Gradle to halt the build rather than guess which version to package. The root cause is usually not the library named in the error message, but a transitive dependency pulling in an older or incompatible version behind the scenes. Common culprits include version mismatches between libraries, outdated third-party packages referencing legacy AndroidX or Google Play Services versions, and manually added Android dependencies that Expo already manages internally. Recommended fixes include identifying the conflicting modules, running Gradle dependency insight commands to trace the source, updating outdated libraries, and clearing the Gradle cache before rebuilding.

TypeScript's Strict Null Checks Won't Save You From Runtime Crashes · ShortSingh