recommended vscode settings/extensions for pentible/typescript-app-template
This file contains hidden or 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
| import type { Job } from "bullmq"; | |
| import { Queue } from "bullmq"; | |
| const queue = new Queue("general"); | |
| interface Handler<Name extends string, Data> { | |
| name: Name; | |
| handler: (job: Job<Data, unknown, Name>) => void; | |
| } |
This file contains hidden or 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
| // NOTE: sendgrid doesn't properly export its ResponseError class, so this type | |
| // (roughly) represents that type (with the type of body fixed) | |
| const sendGridResponseErrorSchema = z.instanceof(Error).and(z.object({ | |
| code: z.number(), | |
| response: z.object({ | |
| headers: z.record(z.string(), z.string()), | |
| body: z.object({ | |
| errors: z.array(z.unknown()) | |
| }) | |
| }) |
This file contains hidden or 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
| // zod schema | |
| z.object({ | |
| // valid if string or: | |
| optional: z.string().optional(), // field not provided, or explicitly `undefined` | |
| nullable: z.string().nullable(), // field explicitly `null` | |
| nullish: z.string().nullish(), // field not provided, explicitly `null`, or explicitly `undefined` | |
| }); | |
| // type | |
| { |
This file contains hidden or 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
| import fs from "fs/promises"; | |
| import { minimatch } from "minimatch"; | |
| import { SemVer, parse, satisfies } from "semver"; | |
| import { z } from "zod"; | |
| type Package = (typeof packages)[number]; | |
| function isNonNullable<T>(val: T): val is NonNullable<T> { | |
| return Boolean(val); | |
| } |
This file contains hidden or 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
| // preferred implementation | |
| export type Result<T, E extends Error> = | |
| | { readonly ok: false; readonly error: E } | |
| | { readonly ok: true; readonly value: T }; | |
| export function Ok<T>(value: T) { | |
| return { ok: true, value } as const; | |
| } | |
| export function Err<E extends Error>(error: E) { |
This file contains hidden or 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
| interface FooEvent { | |
| ack: { ack: string }; | |
| bash: { bash: string }; | |
| bar: { bar: string }; | |
| buzz: { buzz: string }; | |
| } | |
| interface BarEvent { | |
| ack: { ack: string }; | |
| bash: { bash: string }; |
This file contains hidden or 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
| run_script_in_terminal() { | |
| osascript - "$@" <<'EOF' | |
| on FileExists(theFile) -- (String) as Boolean | |
| try | |
| do shell script "ls " & quoted form of theFile & " && ! lsof " & quoted form of theFile | |
| return true | |
| on error errMsg number errNum | |
| return false | |
| end try | |
| end FileExists |
This file contains hidden or 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
| import { z } from "zod"; | |
| export function zStringToNumber() { | |
| return z.preprocess((a) => { | |
| const stringRes = z.string().safeParse(a); | |
| if (!stringRes.success) { | |
| return a; | |
| } | |
| const numberRes = Number.parseInt(stringRes.data); |
NewerOlder