Our great sponsors
-
SurveyJS
Open-Source JSON Form Builder to Create Dynamic Forms Right in Your App. With SurveyJS form UI libraries, you can build and style forms in a fully-integrated drag & drop form builder, render them in your JS app, and store form submission data in any backend, inc. PHP, ASP.NET Core, and Node.js.
The above is caught in Flow when exact types are enabled but not in TS.
TS issue https://github.com/microsoft/TypeScript/issues/12936
TS has a concept of "freshness" which catches some of these mistakes when you construct y right in the arguments of x, but it gets easily broken by accident and without a warning.
2. Nominal types, so you can have for example "Id" type that is a number but not to be mixed with other numbers, you can't just call a function that expects an Id with literal 42. Classes are nominal too, which I think is a solid choise.
3. Type variance & related safeguards
function x(y: { foo: string | number}) {
I know you're entirely right, but sometimes I see things like this in Typescript and although I can walk through it with enough pause, it kinda makes my head implode when I glance at it:
https://github.com/sindresorhus/type-fest/blob/main/source/r...
Related posts
- Preventing more parameters being passed than needed by a type definition?
- pkgroll: zero-config JS bundler for ESM, CommonJS, and .d.ts outputs
- How to implement unit, integration and e2e tests in your node backend with the clean architecture
- TypeScript Essentials: Distinguishing Types with Branding
- Smart Contract Programming Languages: sCrypt vs. Solidity