asdf
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 * as z from "zod"; | |
export const a = z.object({ | |
a: z.string(), | |
b: z.string(), | |
c: z.string(), | |
}); | |
export const b = a.omit({ | |
a: true, |
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 { randomString } from "./benchUtil.js"; | |
import { metabench } from "./metabench.js"; | |
export function lazyWithInternalProp<T>(getter: () => T) { | |
return { | |
__value: undefined as T, | |
get value() { | |
if (this.__value) return this.__value; | |
const value = getter(); | |
this.__value = value; |
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
function lazy<T>(getter: () => T): { value: T } { | |
return { | |
get value() { | |
const value = getter(); | |
Object.defineProperty(this, "value", { value }); | |
return value; | |
}, | |
}; | |
} |
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 * as z from "zod"; | |
const mySchema = z.string(); | |
// there is a global schema registry | |
z.globalRegistry; // => ZodRegistry<unknown, z.ZodType> | |
// add schema to registry w/ associated metadata | |
z.globalRegistry.add(mySchema, { name: "foo", description: "bar" }); | |
// equivalent convenience method (returns mySchema) |
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
alias howto="gh copilot suggest -t shell" |
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
[ | |
{ | |
"key": "cmd+;", | |
"command": "editor.action.goToDeclaration" | |
}, | |
{ | |
"key": "shift+cmd+;", | |
"command": "workbench.action.navigateBack", | |
"when": "canNavigateBack" | |
} |
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
gh repo clone https://github.com/colinhacks/live-typescript-monorepo | |
cd live-typescript-monorepo | |
cd project-references | |
pnpm i | |
code . | |
# open packages/pkg-b/index.ts | |
# see Cannot find module 'pkg-a' or its corresponding type declarations | |
pnpm build # runs `tsc -b` | |
# restart ts server, "Cannot find module" goes away | |
pnpm clean # deletes node_modules in all packages |
Adapted from this recommendation by @jandockx
Despite supporting recursive schemas, passing cyclical data into Zod will cause an infinite loop in some cases.
You can protect against cyclical objects starting an infinite loop (at a performance cost) with the following approach
(using the above jsonSchema
as an example):
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
gh repo clone https://github.com/t3-oss/t3-env t3env | |
cd t3env | |
git checkout @t3-oss/[email protected] | |
pnpm i | |
pnpm update zod --latest --recursive | |
pnpm run build |
NewerOlder