-
The official “TypeScript Handbook” is a good reference for the language. It currently has a few holes that are filled by the release notes and GitHub pull requests (which handbook and release notes link to).
-
“TypeScript Deep Dive” by Basarat Ali Syed was not updated much after 2020 – e.g., it does not cover template string types. But this book is still a valuable resource.
Did I forget anything?
- Single executable applications
- Test runner
util.styleText()
util.parseArgs()
node:sqlite
- File operations:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Experiment: I’m not sure if I would use this myself. | |
const call = Symbol('call'); | |
class Callable { | |
constructor() { | |
// Can’t use .bind() here. Not sure why. Maybe the result doesn’t | |
// interact well with Object.setPrototypeOf(). | |
const _this = (...args) => new.target.prototype[call].call(_this, ...args); | |
Object.setPrototypeOf(_this, new.target.prototype); | |
return _this; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//========== Testing types ========== | |
const expectType = <Type>(_: Type): void => void 0; | |
type TypeEqual<Target, Value> = (<T>() => T extends Target | |
? 1 | |
: 2) extends <T>() => T extends Value ? 1 : 2 | |
? true | |
: false; | |
//========== applyPartial ========== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Q: Why not an object literal? | |
// A: Then you have to create separate constants for the symbols: | |
// https://2ality.com/2025/01/typescript-enum-patterns.html#using-symbols-as-property-values | |
type PropertyValues<Obj> = Obj[keyof Obj]; | |
function createEnum<C extends new (...args: unknown[]) => unknown>(enumClass: C): Omit<C, 'prototype'> { | |
return enumClass; | |
} | |
const Color = createEnum(class { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type CreateTuple<Len extends number, Acc extends unknown[] = []> = | |
Acc['length'] extends Len | |
? Acc | |
: CreateTuple<Len, [...Acc, true]>; | |
; | |
type Length<Tup extends Array<unknown>> = | |
Tup['length'] | |
; | |
type Unshift<Tuple extends Array<unknown>, Value> = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This code is now an npm package: https://github.com/rauschma/asserttt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Slightly modified version of: https://github.com/es-shims/RegExp.escape/blob/main/test/tests.js | |
import test from 'node:test'; | |
import assert from 'node:assert/strict'; | |
import {regExpEscape as escape} from './regexp-escape.mjs'; | |
const forEach = (arrayLike, callback) => Array.prototype.forEach.call(arrayLike, callback); | |
const inspect = String; | |
test('strings', function (st) { |
In this blog post, I try to explain Mastodon to people who are not familiar with social media and/or beginner computer users. I try to be as jargon-free as I can.
Structure of this blog post:
-
Reading section 1 and 2 takes a bit of effort: They explain important background knowledge for Mastodon. But, in my opinion, the effort is worth it because you’ll find it much easier to use Mastodon. Not having this knowledge can prevent even otherwise advanced computer users from enjoying Mastodon.
-
Section 3 is brief and mentions first steps for actually getting started with Mastodon.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript:{ | |
const text = getSelection().toString().trim(); | |
if (text.length > 0) { | |
const urlToHighlight = new URL(location); | |
urlToHighlight.hash = '#:~:text=' + encodeURIComponent(text); | |
navigator.clipboard.writeText(urlToHighlight.href) | |
.catch((error) => { | |
alert(String(error)); | |
}); | |
} |
NewerOlder