Skip to content

Fix TypeScript-only syntax in docs snippets embedded as JavaScript - #519

Merged
techwritermat merged 1 commit into
masterfrom
docs-snippets-platform-review-fixes
Sep 23, 2026
Merged

techwritermat merged 1 commit into
masterfrom
docs-snippets-platform-review-fixes

Conversation

@techwritermat

Copy link
Copy Markdown
Contributor

What

Makes every docs-snippets region that the documentation renders as JavaScript valid plain JavaScript, while keeping the files type-checked by npm run test:snippets.

  • Replaces the (error as PubNubError).status catch-block ternaries (54 occurrences) with console.error(`<operation> failed: ${error}`).
  • Removes the now-unused PubNubError imports.
  • Removes (channel: string) => parameter annotations in mobile-push.ts and channel-groups.ts.
  • Restructures the React Native file-download snippet so it no longer needs a ! non-null assertion.

Snippet names and // snippet.* boundaries are unchanged, so every existing docs page that embeds these regions keeps working.

Files: docs-snippets/basic-usage/{app-context,channel-groups,file-sharing,message-persistence,mobile-push,presence}.ts, docs-snippets/{message-persistence,presence}.ts. DataSync and use-cases/ files are not touched.

Why

Documentation review finding G01 (Platform docs release review, preview 961): the docs embed these .ts files with language="javascript". The extracted regions contained TypeScript-only syntax, so code copied from a "JavaScript" tab failed node --check before any PubNub call.

Validation

  • npm run test:snippets passes.
  • All 28 JavaScript regions embedded by the 14 affected Platform pages were extracted with the docs site's own extractSnippets (src/helper/codeSnippetFetcher.ts) from this branch, and each passes node --check as an ES module.

Docs dependency

The docs pages already point at refs/heads/master, so they pick up the fix automatically when this merges. No docs URL change is needed.

Platform docs review (G01): EmbeddedCode blocks labeled javascript on
non-sports pages (files, message-persistence, app-context, mobile-push,
presence, channel-groups basic-usage snippets, plus message-persistence.ts
and presence.ts) failed node --check because catch blocks used
`(error as PubNubError).status` casts, and a couple of snippets used
`(channel: string) =>` parameter annotations and a `file!` non-null
assertion. Replace the cast-based status message with a plain
`console.error(`<op>: ${error}`)`, drop the now-unused PubNubError import,
remove the two type annotations, and restructure the React Native download
snippet so it never needs a non-null assertion. `npm run test:snippets`
(tsc --project docs-snippets/tsconfig.json --noEmit) still passes, and
every affected snippet region now also passes node --check.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Sep 23, 2026

Copy link
Copy Markdown

Important

Review skipped

Review was skipped due to path filters

⛔ Files ignored due to path filters (8)
  • docs-snippets/basic-usage/app-context.ts is excluded by none and included by none
  • docs-snippets/basic-usage/channel-groups.ts is excluded by none and included by none
  • docs-snippets/basic-usage/file-sharing.ts is excluded by none and included by none
  • docs-snippets/basic-usage/message-persistence.ts is excluded by none and included by none
  • docs-snippets/basic-usage/mobile-push.ts is excluded by none and included by none
  • docs-snippets/basic-usage/presence.ts is excluded by none and included by none
  • docs-snippets/message-persistence.ts is excluded by none and included by none
  • docs-snippets/presence.ts is excluded by none and included by none

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

⚙️ Run configuration

Configuration used: Repository: pubnub/javascript/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 8b1bcf10-c14d-4ad7-9f0e-4a52c3936caa

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pubnub-ops-terraform

pubnub-ops-terraform commented Sep 23, 2026 •

Copy link
Copy Markdown

✅ Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
✅ Open Source Security 0 0 0 0 0 issues
✅ Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@mohitpubnub mohitpubnub left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Its a bit less informative error handling but at the same time for plain JS we can go with this

@techwritermat
techwritermat merged commit b91b255 into master Sep 23, 2026
19 of 30 checks passed
@techwritermat
techwritermat deleted the docs-snippets-platform-review-fixes branch September 23, 2026 11:05
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.

3 participants