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
  • Appwrite - The open-source backend cloud platform
  • Onboard AI - Learn any GitHub repo in 59 seconds
  • Revelo Payroll - Free Global Payroll designed for tech teams
  • InfluxDB - Collect and Analyze Billions of Data Points in Real Time
  • Sonar - Write Clean JavaScript Code. Always.
  • 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.

  • Appwrite

    Appwrite - The open-source backend cloud platform. The open-source backend cloud platform for developing Web, Mobile, and Flutter applications. You can set up your backend faster with real-time APIs for authentication, databases, file storage, cloud functions, and much more!

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

    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.

  • Onboard AI

    Learn any GitHub repo in 59 seconds. Onboard AI learns any GitHub repo in minutes and lets you chat with it to locate functionality, understand different parts, and generate new code. Use it for free at www.getonboard.dev.

  • 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