Posted on

Using Boxing to prevent distribution of conditional types

TypeScript conditional types have an interesting property that they can “distribute” over union types. As explained better by the official docs:

Conditional types in which the checked type is a naked type parameter are called distributive conditional types. Distributive conditional types are automatically distributed over union types during instantiation. For example, an instantiation of T extends U ? X : Y with the type argument A | B | C for T is resolved as (A extends U ? X : Y) | (B extends U ? X : Y) | (C extends U ? X : Y).

While I understand the rationale behind this behavior, this can sometimes lead to somewhat non-intuitive outcomes in real-world scenarios:

Continue reading Using Boxing to prevent distribution of conditional types

Posted on

Kickstart your full stack GraphQL application with GRelDAL starter – III

In the first post of this series we have looked at how to rapidly bootstrap your full stack graphql application scaffold using GRelDAL starter. In the next post we have explored what all is happening in the backend of this scaffold and got a taste of how GRelDAL helps us easily connect to relational databases and expose the data stored in them as a user friendly graphql API.

In this post we will look at how to talk to the backend using the Apollo client and how to build a react based frontend using this API.

Posted on

Kickstart your full stack GraphQL application with GRelDAL starter – II

In the previous post of this series, we tried out the GRelDAL starter and bootstrapped a simple application.

In this (and the next) post, we dig deeper into what is happening in the application, and then in the last two posts of the series, we will extend this application to build something more closely resembling a real world app.

Posted on

Using theme specific keybindings in VSCode to improve productivity

I have been using VSCode as my primary editor for a couple of months. However it has been a recurring pain point for me that we have to switch back and forth between the arrow keys and primary rows when editing code. This post outlines a somewhat non-conventional approach for this by abusing the when clause of vscode keybinding configuration.

Continue reading Using theme specific keybindings in VSCode to improve productivity

Posted on

Exposing the type of a typescript class while hiding the implementation

When we define a typescript class, we are actually defining two things, a constructor function, and a type. The instances constructed using the constructor defined by a class will have the type of the class.

One might wonder, if it is possible, say from a library, to expose only the type of the class and not the actual type constructor. The goal here may be to prevent direct instantiation of the class, or prevent consumers from monkeying around with the prototype chain of the constructor.

Continue reading Exposing the type of a typescript class while hiding the implementation

Posted on

Using an SVG grid background for aligning elements in web page

One of the recurring annoyances when designing websites is ensuring alignment of elements on a web page.

Most design applications have the provision of an overlay grid. With very little effort we can add a simple grid to any web page and use it to ensure alignment of elements.

Continue reading Using an SVG grid background for aligning elements in web page

Posted on

Simplifying generics-heavy typescript code using Container Interfaces, Extractor Types and Companion Namespaces

Writing generics-heavy code code in Typescript can sometimes be arduous, especially because typescript doesn’t facilitate higher kinded types at language level.

So, a function that accepts multiple arguments of generic types often has to accept type parameters of all these generic types in order to retain type safety:

This can get cumbersome fast, especially when the parameterized types have constraints on the type parameters because now these constraints also have to be replicated:

Continue reading Simplifying generics-heavy typescript code using Container Interfaces, Extractor Types and Companion Namespaces

Posted on

Integrating Google diff-match-patch with AutoMerge.Text

This post outlines the use of Google’s diff-match-patch library to generate patches that can be translated to operations against an AutoMerge.Text CRDT for situations when deriving the operations directly from user interactions is cumbersome.
Continue reading Integrating Google diff-match-patch with AutoMerge.Text