Tag: TypeScript
-
Client-side environment variables with Next.js
Next.js does a great job with environment variables. Out of the box, it supports loading up environment variables in next.config.js as well as using a .env file. Both of which are made available inside of server components. For client-side components though, you don’t get direct access to environment variables from both locations. The Next.js config…
-
Including Dev Dependencies in a DigitalOcean App Platform Build
When working with dependencies in a DigitalOcean App Platform build, there are time when you may need to include development dependencies. Such instances arise when you’re using something like TypeScript, which you’d typically have listed in your devDependencies because it’s not a necessary dependency once you’ve transpiled your code and shipped it to production. Out…
-
Convert string to number with JavaScript
Been working through swapping a MySQL library recently to prepare for a major database upgrade. The old library would return the results from function like AVG and SUM as a number. The new library, not so much. MySQL natively returns those values as strings, which I can applaud the library for respecting. Coming from a…
-
Numeronym in JavaScript
Numeronyms are a form of abbreviation. The middle of the word or phrase is swapped out for a number that represents the number of letters that are being replaced. The first and last letters are retained. Some examples are: I’m not really a fan of the word “numeronym”, primarily because I can’t ever seem to…
-
Stop ESLint from searching up the directory tree
For most projects, I use a monorepo, and nest my scripts in a directory. I’ll npm init each script, and maintain an isolated set of dependencies outside of the main dependency tree. This includes maintaining a separate .eslintrc file as well. Typically, this isn’t a problem, but recently with a new project that was created…
-
Airbnb style guide with Next.js
Starting a fresh Next.js project the other day, I was happy to see that configuring eslint was part of the bootstrapping process. Where things fell short for me, was the lack of a prompt asking me which style guide I’d like to use. I’m sure the out of the box option is sufficient enough, and…
-
Best way to pin TypeScript as a dependency
While I’m a pretty big fan of TypeScript, there’s some stuff that drives me up a wall. One of those things recently came to light during the release of TypeScript 4.4 on a Friday afternoon. So it was nearing both end of day and end of week, and we were…
-
Recursive functions in TypeScript
In working with the Slate framework for building rich text editors recently, I found myself faced with a scenario where I needed to loop through the editor’s value. The value that comes out the editor is an array of objects that is nestable, I assume infinitely, by way of the…
-
Recursive types and interfaces in TypeScript
When writing out a type or interface in TypeScript for something that will be fed into a recursive function you could cop out and use any or you could properly define the structure. Fortunately, both type and interface allow you to be self referential in terms of defining properties. Let’s…
-
Error: Cannot resolve a DOM point from Slate point
By way of recommendation (thanks Brewer), I’ve been messing around with Slate.js a ton. Such is life, I did have my fair share of issues, particularly in terms of getting it to function like a chat message input where hitting Enter will submit the form and reset it to it’s…