Skip to content

Instantly share code, notes, and snippets.

View ssalbdivad's full-sized avatar

David Blass ssalbdivad

View GitHub Profile

TypeScript Type Performance Cheat Sheet

Principles

1. Build up, not down

Combine sets of properties using interface extensions rather than extracting them using utilities like Omit.

Handling The inferred type of x cannot be named without a reference to y

This error is notoriously fickle to reproduce or resolve. It can always be fixed by adding an export type for a name TS needs to compile your types. Here's how to find where the change needs to be made:

  1. Navigate to the source of the diagnostic in the repo's _tsc.js file (line 52151 as of TS 5.7.3). You can search for reportLikelyUnsafeImportRequiredError to see all references to it if needed. Add a breakpoint in at that position:
if (!attributes) {
  // ADD BREAKPOINT HERE ⬇️
 context.encounteredError = true
@ssalbdivad
ssalbdivad / ArkTypeVsZod.md
Last active December 10, 2025 03:53
ArkType/Zod Comparison

Here's a comparison between how the same simple user definition would be defined using ArkType and Zod:

image

ArkType's definition syntax is more concise (definitions are about 50% shorter on average) as well as making it more visually obvious what the inferred TypeScript type will be. The ability to infer TypeScript definitions directly is the same, but ArkType's syntax is again more concise by allowing you to use typeof on a property of arkUser directly instead of using an extra "infer" helper.

In general, we also have taken significant steps to optimize and clarify our type hints when hovering over validators. For example, in the case above, this is what you see when you mouse over "zodUser":

image

@ssalbdivad
ssalbdivad / cloudSettings
Last active January 21, 2020 19:09
Visual Studio Code Settings Sync Gist
{"lastUpload":"2020-01-21T19:09:52.174Z","extensionVersion":"v3.4.3"}