TypeScript Tricks I wish I knew when I learned TypeScript

This page summarizes the projects mentioned and recommended in the original post on news.ycombinator.com

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

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

    Short comment about the 'unknown' type: TypeScript 4.4 had me learning about it very recently, because 'unknown' has been made the default type in 'catch (error)' clauses [0]. So most of our code in 'catch' blocks suddenly didn't compile any more after an unsuspecting update of the TS version.

    Which is a good thing, because in reviewing those I found several places where incorrect assumptions were being made about the type of error that would be caught.

    (side note: TypeScript does not follow SemVer; they just promise to avoid breaking changes in Patch updates, but don't promise anything won't break in Minor updates [1])

    [0]: https://devblogs.microsoft.com/typescript/announcing-typescr...

    [1]: https://github.com/microsoft/TypeScript/issues/14116#issueco...

  • lodash

    A modern JavaScript utility library delivering modularity, performance, & extras.

    Probably best to just lift one off of a major library like Lodash, they're well tested and efficient (no need to actually use the library):

    https://github.com/lodash/lodash/blob/master/isObject.js

    But depends on your needs, and you can also attach a typeguard to it.

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

  • @sindresorhus/is

    Type check values (by sindresorhus)

    I really like this package, because it not only uses the method you mentioned for checking types, but is written in TS, so you get the type checking feedback.

    https://github.com/sindresorhus/is

  • typing-euler

    Discontinued Typing Euler because values are code smells

  • graphql-js

    A reference implementation of GraphQL for JavaScript

    > I have only seen null vs undefined lead to 2 things in my experience: mistakes and bikeshedding.

    I disagree, though I think the implementation leaves something to be desired. Primarily, I think there is fundamentally a difference between the value of obj.bar in the following examples that is useful to differentiate between:

    { foo: 'hello' }

    { foo: 'hello', bar: null }

    For example, GraphQL makes specific use of this when dealing with input types for mutations: null essentially means "delete this field" while unset means "don't change it".

    There is a very good discussion on this topic here, https://github.com/graphql/graphql-js/issues/133 , which goes into the rationale behind it, how it's supported in languages that do NOT differentiate between null and undefined, and how some folks changed their minds on the issue.

  • milewski-ctfp-pdf

    Bartosz Milewski's 'Category Theory for Programmers' unofficial PDF and LaTeX source

    You don't need a PhD, you just need the first few chapters of [Category Theory for Programmers](https://github.com/hmemcpy/milewski-ctfp-pdf) :)

  • ts-sql

    A SQL database implemented purely in TypeScript type annotations.

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

  • json-parser-in-typescript-very-bad-idea-please-dont-use

    JSON Parser written entirely in TypeScript's type system

  • typanion

    Static and runtime type assertion library with no dependencies

  • Yup

    Dead simple Object schema validation

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