Skip to content

Instantly share code, notes, and snippets.

View virtuallyunknown's full-sized avatar

virtuallyunknown

View GitHub Profile
@virtuallyunknown
virtuallyunknown / filter.ts
Created June 26, 2023 00:41
TS: Recursively filter out branches of an array of items (by set criterion)
type Expand<T> = T extends infer O ? { [K in keyof O]: O[K] } : never;
const commands = [
{
name: 'foo',
options: [
{ name: 'foo-string', type: 'STRING', autocomplete: true },
{ name: 'foo-integer', type: 'INTEGER' },
],
},
@virtuallyunknown
virtuallyunknown / kysely-runtime.js
Last active April 25, 2023 02:08
Generate runtime types from .ts file generated by kysely-codegen.
import { readFile, writeFile } from "node:fs/promises";
import { normalize } from "node:path";
import { inspect } from "node:util";
import { Project } from "ts-morph";
async function tryReadFile(path) {
try {
return await readFile(path, { encoding: "utf-8" });
} catch {
return null;