fix(docs): make cookbook + README examples runnable as plain JS#12
Merged
fix(docs): make cookbook + README examples runnable as plain JS#12
Conversation
There was a problem hiding this comment.
Pull request overview
Updates the project documentation so cookbook and README code samples can be executed directly as plain JavaScript (ES modules) without TypeScript-only syntax causing runtime SyntaxErrors.
Changes:
- Convert relevant documentation code blocks from
tstojsand remove TS-only syntax (type guards, generics, non-null assertions). - Add brief “how to run” guidance for Node (and TS via
tsx) to the cookbook and README. - Fix the missing
MAGIC_KINGDOMconstant in Cookbook Recipe 5’s generic alternative example.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| docs/cookbook.md | Makes all recipe snippets plain-JS runnable; adds run instructions; fixes missing constant in Recipe 5 alt snippet. |
| README.md | Makes README snippets plain-JS runnable and removes TS-only syntax from examples; clarifies the one TS-only cache adapter example. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+17
to
+19
| Every example in this README works as plain JavaScript — save as `.mjs` and | ||
| run with `node`. To use them as TypeScript, rename to `.ts` and run with | ||
| `npx tsx`; the SDK ships full `.d.ts` types so TypeScript infers everything. |
| ```ts | ||
| Every example in this README works as plain JavaScript — save as `.mjs` and | ||
| run with `node`. To use them as TypeScript, rename to `.ts` and run with | ||
| `npx tsx`; the SDK ships full `.d.ts` types so TypeScript infers everything. |
Cookbook and README code blocks were labeled \`ts\` but mixed TS-only syntax (type guards, generics, non-null assertions) into runnable examples. A user copy-pasting into \`test.mjs\` and running with node hit SyntaxErrors. Also Recipe 5's generic-alternative block referenced MAGIC_KINGDOM without declaring it. - Rename runnable blocks from \`ts\` to \`js\` and strip TS-only syntax. - Keep the single TypeScript example (Cache adapter with \`implements\`) labeled \`ts\` with a note on how to translate. - Add a preamble in both docs explaining the js vs ts file-extension swap so users know which runtime to use. - Add the missing MAGIC_KINGDOM constant in the generic-alternative block. - Replace \`wdw!.id\` (TS non-null assertion) with a real entity id in the low-level escape-hatch example. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
d882dd1 to
261d589
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Users running the examples with node hit SyntaxErrors because
tsblocks had TS-only syntax (type guards, generics,!assertions). Rewrote for plain JS, kept the one real-TS example clearly labeled, and fixed a missing constant in Recipe 5.