Blog Page 2

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.

Component Library Checklist

The following is a checklist I like to use to ensure I'm covering all the bases when building a component library. It's a work in progress, but I hope it can be useful to others.

Debugging slow tsc

I was working on a project and I noticed the tsc check that we ran on pre-commit hooks had become dramatically slower. I was seeing near instant times to type check the entire project go to agonizingly slow minutes to check the project. I was able to narrow the range of commits to some change we made within a month window. I’m sure I could have narrowed it down by continuing to git bisect and re-running time npx tsc, but it was much easier to just check out main and try out the following: