Keyboard Shortcuts for Jumping and Deleting in iTerm2
Marius Schulz Blog
by Marius Schulz
2y ago
As a software engineer, I find myself using the terminal every day to run all sorts of commands. My current terminal of choice is iTerm2 which I’ve been using happily for many years. Whenever I set up iTerm2 on a new Mac, one of the first things I do is to configure familiar keyboard shortcuts for common navigation and edit actions in the command prompt. For example, I typically configure the ⌥← shortcut which jumps me to the start of the word under the cursor. To configure custom keyboard shortcuts in iTerm2, open the preferences dialog and navigate to the Profiles › Keys › Key Mappings tab ..read more
Visit website
Optional Chaining: The ?. Operator in TypeScript
Marius Schulz Blog
by Marius Schulz
2y ago
TypeScript 3.7 added support for the ?. operator, also known as the optional chaining operator. We can use optional chaining to descend into an object whose properties potentially hold the values null or undefined without writing any null checks for intermediate properties. Optional chaining is not a feature specific to TypeScript. The ?. operator got added to the ECMAScript standard as part of ES2020. All modern browsers natively support optional chaining (not including IE11). In this post, I will go over the following three optional chaining operators and explain why we might want to use the ..read more
Visit website
How to Squash the First Two Commits in a Git Repository
Marius Schulz Blog
by Marius Schulz
3y ago
I recently needed to squash the first two commits in one of my Git repositories. As usual, I ran the git rebase -i command to do an interactive rebase, but I noticed that the root commit didn't appear in the list of commits. Here's what my Git history looked like: $ git log --graph --oneline * fe2c946 (HEAD -> main) More changes * 2702f8b Small tweaks * ffb98dd Initial commit When I ran git rebase -i ffb98dd, this was the output I got (omitted for brevity): pick 2702f8b Small tweaks pick fe2c946 More changes # Rebase ffb98dd..fe2c946 onto ffb98dd (2 commands) # ... As you can see, the ..read more
Visit website
Nullish Coalescing: The ?? Operator in TypeScript
Marius Schulz Blog
by Marius Schulz
4y ago
TypeScript 3.7 added support fort the ?? operator, also known as the nullish coalescing operator. We can use this operator to provide a fallback value for a value that might be null or undefined. Truthy and Falsy Values in JavaScript Before we dive into the ?? operator, let's recall that JavaScript values can either be truthy or falsy: when coerced to a Boolean, a value can either produce the value true or false. In JavaScript, the following values are considered to be falsy: false 0 -0 0n NaN "" null undefined All other JavaScript values will produce the value true when coerced to a Boolean ..read more
Visit website
The Omit Helper Type in TypeScript
Marius Schulz Blog
by Marius Schulz
4y ago
In version 3.5, TypeScript added an Omit<T, K> helper type to the lib.es5.d.ts type definition file that ships as part of the TypeScript compiler. The Omit<T, K> type lets us create an object type that omits specific properties from another object type: type User = { id: string; name: string; email: string; }; type UserWithoutEmail = Omit<User, "email">; // This is equivalent to: type UserWithoutEmail = { id: string; name: string; }; The Omit<T, K> helper type is defined in lib.es5.d.ts like this: /** * Construct a type with the properties of T except for those in t ..read more
Visit website
Declaring Global Variables in TypeScript
Marius Schulz Blog
by Marius Schulz
4y ago
Every now and then, you might want to statically type a global variable in TypeScript. For example, in some of my web applications, I need to pass a few properties from my markup rendered on the server to my JavaScript code running in the browser. To do that, I typically define a global variable named __INITIAL_DATA__ within an inline script and assign to it a JSON-serialized object: <script> window.__INITIAL_DATA__ = { "userID": "536891193569405430" }; </script> Now, if I try to access window.__INITIAL_DATA__ in a TypeScript file, the compiler will produce a type error because ..read more
Visit website
Concatenating Arrays in JavaScript
Marius Schulz Blog
by Marius Schulz
4y ago
It's a common task to concatenate multiple arrays into a single one. In JavaScript, there are several different approaches we can take. Some of them mutate the target array; others leave all input arrays unchanged and return a new array instead. In this post, I want to compare the following common approaches: Appending elements to an existing array with Array.prototype.push() Appending elements to a new array with Array.prototype.push() Concatenating multiple arrays with Array.prototype.concat() Using spread syntax in an array literal Let's take a look. Appending Elements to an Existing Arra ..read more
Visit website
Const Assertions in Literal Expressions in TypeScript
Marius Schulz Blog
by Marius Schulz
4y ago
With TypeScript 3.4, const assertions were added to the language. A const assertion is a special kind of type assertion in which the const keyword is used instead of a type name. In this post, I'll explain how const assertions work and why we might want to use them. Motivation for const Assertions Let's say we've written the following fetchJSON function. It accepts a URL and an HTTP request method, uses the browser's Fetch API to make a GET or POST request to that URL, and deserializes the response as JSON: function fetchJSON(url: string, method: "GET" | "POST") { return fetch(url, { method ..read more
Visit website
Fast Searching with ripgrep
Marius Schulz Blog
by Marius Schulz
4y ago
In this post, I want to introduce you to ripgrep, a smart and fast command line search tool that I find myself using all the time when programming. ripgrep recursively searches directories for a regex pattern and outputs all matches that it finds. Why ripgrep? So what makes ripgrep so great? After all, there are plenty of other search tools out there already, like grep, ack, or The Silver Searcher. For me, it boils down to the following reasons: ripgrep is smart. It picks sensible defaults out of the box. I like that! For example, ripgrep respects .gitignore files and skips matching files and ..read more
Visit website
The --showConfig Compiler Option in TypeScript
Marius Schulz Blog
by Marius Schulz
4y ago
TypeScript 3.2 added a new --showConfig compiler flag to the tsc executable. The command tsc --showConfig calculates the effective tsconfig.json file and prints it to the console. This is useful for debugging configuration issues, particularly when used in conjunction with the extends property in a tsconfig.json file. The --showConfig Flag Let's look at an example to understand what the --showConfig flag does. Going forward, I'm assuming the following directory structure: . ├── main.ts ├── tsconfig.json └── utils └── crypto.ts Here's what's inside the tsconfig.json file: { "compilerOptions ..read more
Visit website

Follow Marius Schulz Blog on FeedSpot

Continue with Google
Continue with Apple
OR