Recently I had to write a type-safe function that allowed to update (nested) paths of a JavaScript object. I wanted the function to prevent setting a wrong value to the requested path, even nested ones with optional values.
After playing a bit with TypeScript type system I came up with these types which I think can be useful and will be using for sure in future projects. You can play with it in this playground or see the code right below:
exporttype KeyPath<
T extendsstring,
K extendsstring,
Separator extendsstring = ".",
> = `${T}${""extends T ? "" : Separator}${K}`;
exporttype KeyPaths<T extends object, P extendsstring = "", Separator extendsstring = "."> = {
[K in keyof T]-?: K extendsstring ? NonNullable<T[K]> extends object
? KeyPath<P, K, Separator> | KeyPaths<NonNullable<T[K]>, KeyPath<P, K, Separator>, Separator>
: KeyPath<P, K, Separator>
: never;
}[keyof T & string];
exporttype GetTypeAtKeyPath<T, Path extendsstring, Separator extendsstring = "."> = Path extends keyof T
? T[Path]
: Path extends`${infer K}${Separator}${infer Rest}` ? K extends keyof T
? NonNullable<T[K]> extends object
? GetTypeAtKeyPath<NonNullable<T[K]>, Rest, Separator>
: never
: never
: never;
Code language:TypeScript(typescript)
Modern front-end developer experience is nicer than the one we had in 2007 when WordPress came out.
CSS preprocessors help you reduce boilerplate and reuse mixins.
TypeScript minimizes runtime errors with its type-checking and IDE auto-completion.
The latest syntactic sugar from ECMAScript drafts makes your code simpler.
Partial content refresh when files change with HMR enables a seamless experience.
Regular WordPress themes require reloading the entire page when any JavaScript or CSS changes. However, with tools like Vite we can achieve a state-of-the-art developer experience.
In this post I will guide you through all the steps required to add SASS, TypeScript, and HMR support to any WordPress theme.
A Twenty Twenty child theme with SASS stylesheet and HMR, and early preview of what we will achieve by the end of the post.Read more →
This post was published 2 years ago so it might be outdated.
JVM ecosystem has a steep learning curve: missing a Maven/Gradle dependency might end up being a cryptic runtime exception about a package that is partially referenced in an XML file. I experienced this recently at work, trying to set up Log4j2 to write JSON logs in an AWS Lambda function.
This post was published 3 years ago so it might be outdated.
When you build a Docker image you will notice a “transferring context” step in the output (“Sending build context to Docker daemon” in older Docker versions) that can take a lot of time. This step is just Docker copying local files so keeping those to the minimum will make this step faster.
This post was published 4 years ago so it may be outdated.
throttle and debounce are two functions widely used in frontend applications but they are confusing and oftentimes used interchangeably even though they are not the same thing. In this article we’ll review both and clarify their differences (or go directly to the interactive demo showcasing the differences).
This post was published 4 years ago so it may be outdated.
It’s easy to make Docker images bigger than needed. This has a negative impact in both push and pull time but it may also be hiding additional problems you should address before they become critical.
In this post I will explain you three techniques to help you slim down your Docker images:
This post was published 5 years ago so it may be outdated.
There are days when you know you are working on something amazing. You would love to share it with the world, but cannot. I felt that every single day at the office for months, knowing that someday – eventually – I would be able to share this project. Finally – today – Geoblink’s Design System has been open sourced (GitHub repository).
This post was published 5 years ago so it may be outdated.
Jenkins pipelines are cool but writing Jenkinsfiles is a frustrating experience, especially if you are not familiar with Groovy. Testing them can be tedious, too. And to add insult to injury, editor support is not quite good.
However, there are ways to make Jenkinsfile development less painful. One quality of life improvement is being able to validate a Jenkinsfile while developing it, directly in VSCode.
To add linter-like support for Jenkinsfiles in VSCode, take a look at Jenkins Pipeline Linter Connector extension (view).
This post was published 8 years ago so it may be outdated.
Recently I’ve released two iOS games (with Javier Rodríguez Vidal‘s and Víctor Grau Moreso‘s help). Both games use Cocos2d-x engine and a custom open source framework built on top of it named MawKit which I want to introduce in this post.