Skip to content

fix(docs): make cookbook + README examples runnable as plain JS#12

Merged
cubehouse merged 1 commit intomainfrom
fix/docs-plain-js-examples
Apr 15, 2026
Merged

fix(docs): make cookbook + README examples runnable as plain JS#12
cubehouse merged 1 commit intomainfrom
fix/docs-plain-js-examples

Conversation

@cubehouse
Copy link
Copy Markdown
Member

Users running the examples with node hit SyntaxErrors because ts blocks 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.

Copilot AI review requested due to automatic review settings April 15, 2026 14:18
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ts to js and 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_KINGDOM constant 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 thread README.md
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.
Comment thread README.md
```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>
@cubehouse cubehouse force-pushed the fix/docs-plain-js-examples branch from d882dd1 to 261d589 Compare April 15, 2026 14:26
@cubehouse cubehouse merged commit 52654a8 into main Apr 15, 2026
3 checks passed
@cubehouse cubehouse deleted the fix/docs-plain-js-examples branch April 15, 2026 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants