Blog Page 2

Enforcing Localization through Types

When building web applications, enforcing that strings be localized to the user's preferred language can sometimes be achieved via lint rules. But what if we could enforce proper localization using types in TypeScript?

Feature Contexts

A common pattern in larger application when trying to track feature usage is to try to namespace events. For example, you might have a button that you want to track clicks on. For the sake of this article, we will use the data-track attribute on elements to track their usage, but you can imagine this works with any tracking implementation where you may need to explicitly call a tracking function (e.g. track(namespace)).

Forbidden Typescript: full/partial objects

When trying to be as type-safe as possible in Typescript, there are times when you may have to dynamically construct an object. You know as a programmer that all the keys will have values, but because you have to dynamically construct the values, the type system doesn’t know that the object is complete:

Reviewing Your Frontend Applications

Below are some notes I’ve taken from setting up new code repositories and onboarding new team members. Hopefully they can help improve your current documentation and notes to make onboarding a smooth process.

Forbidden Typescript: ensuring all of a type

When creating more complex systems, there are times where you will want to ensure that an array contains every value of a defined type. We have a union of primitive literal types to define the possible values a type can have:

Smart Contract Security

The crypto craze has died down, but if you are working on Smart Contracts or thinking about creating a new blockchain projects, security is a huge part of making sure the project is successful. Since Smart Contracts often interact with cryptocurrencies, blockchain assets, or other tokens, it’s important to make sure the Smart Contract is secure and follows best practices.

Forbidden Typescript: Get Class Name

We don’t get a lot of information using typeof in JavaScript or TypeScript. At most, it tells us whether a value is undefined, number, string, or object. If you want to get the class name using a function, you can use the following extended version of classOf that is originally from ā€œJavaScript: The Definitive Guideā€:

Forbidden Typescript: Enumerating Properties

In ā€œJavaScript: The Definitive Guideā€, there are functions described in 6.5 Enumerating Properties that probably shouldn’t be used in production code because they modify their input parameters: extend, merge, restrict, and subtract.

Forbidden Typescript: Using Object.create to clone

In ā€œJavascript: The Definitive Guideā€ there is an example that uses Object.inherit to inherit the prototype change. JavaScript defines a method Object.create that creates a new object using the given argument as the prototype of that object. Translating the examples from The Definitive Guide to Typescript, it looks like:

Data on the Wire

Back when Meteor was in vogue, they popularized the concept of ā€œData on the wireā€. This was the idea that the UI would be updated with changes from the dataset it is subscribed to.