How to check that an 'unknown' object has a specific key and that the key is a specific type?

This page summarizes the projects mentioned and recommended in the original post on /r/typescript

Our great sponsors
  • SurveyJS - Open-Source JSON Form Builder to Create Dynamic Forms Right in Your App
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • WorkOS - The modern identity platform for B2B SaaS
  • Superstruct

    A simple and composable way to validate data in JavaScript (and TypeScript).

  • ⭐ Recommended: Doing this manually is a ton of work, and if you're dealing with unknown objects often it would be better to lean onto a validation library to simplify it. My personal favorite is superstruct, although lots of people like joi or zod. They all do the same thing

  • joi

    Discontinued The most powerful data validation library for JS [Moved to: https://github.com/hapijs/joi]

  • ⭐ Recommended: Doing this manually is a ton of work, and if you're dealing with unknown objects often it would be better to lean onto a validation library to simplify it. My personal favorite is superstruct, although lots of people like joi or zod. They all do the same thing

  • 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.

    SurveyJS logo
  • zod

    TypeScript-first schema validation with static type inference

  • ⭐ Recommended: Doing this manually is a ton of work, and if you're dealing with unknown objects often it would be better to lean onto a validation library to simplify it. My personal favorite is superstruct, although lots of people like joi or zod. They all do the same thing

  • runtypes

    Runtime validation for static types

  • Seconding the recommendation to use a library for this. runtypes and io-ts are two other alternatives.

  • io-ts

    Runtime type system for IO decoding/encoding

  • Seconding the recommendation to use a library for this. runtypes and io-ts are two other alternatives.

  • InfluxDB

    Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.

    InfluxDB logo
NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts