For sale in Munich (to be picked up in person): EUR 700
- Original price (2024-05-20): €1269
- Intel Core i5-1340P (13th Gen)
- RAM: 2 × 16GB (DDR4-3200)
- SSD: 500GB (WD_BLACK SN770 NVMe)
- Expansion “cards” (that slot into the laptop case):
- 2 USB-C
For sale in Munich (to be picked up in person): EUR 700
// More information on enum objects as an alternative to enums: | |
// https://2ality.com/2025/01/typescript-enum-patterns.html#alternative-to-enum%3A-object-literal-1 | |
/** | |
* Returns an enum object. Adds the following improvements: | |
* - Sets the prototype to `null`. | |
* - Freezes the object. | |
* - The result has the same type as if `as const` had been applied. | |
*/ | |
function createEnum< |
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?
util.styleText()
util.parseArgs()
node:sqlite
// 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; |
//========== 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 ========== |
// 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 { |
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 code is now an npm package: https://github.com/rauschma/asserttt |
// 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) { |