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 reddit.com/r/typescript

Our great sponsors
  • Appwrite - The Open Source Firebase alternative introduces iOS support
  • InfluxDB - Access the most powerful time series database as a service
  • Sonar - Write Clean JavaScript Code. Always.
  • 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

    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

  • Appwrite

    Appwrite - The Open Source Firebase alternative introduces iOS support . Appwrite is an open source backend server that helps you build native iOS applications much faster with realtime APIs for authentication, databases, files storage, cloud functions and much more!

  • 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

    Access the most powerful time series database as a service. Ingest, store, & analyze all types of time series data in a fully-managed, purpose-built database. Keep data forever with low-cost storage and superior data compression.

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