Fix TypeScript-only syntax in docs snippets embedded as JavaScript - #519
Conversation
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>
|
Important Review skippedReview was skipped due to path filters ⛔ Files ignored due to path filters (8)
CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including ⚙️ Run configurationConfiguration used: Repository: pubnub/javascript/.coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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. Comment |
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
mohitpubnub
left a comment
There was a problem hiding this comment.
Its a bit less informative error handling but at the same time for plain JS we can go with this
What
Makes every
docs-snippetsregion that the documentation renders as JavaScript valid plain JavaScript, while keeping the files type-checked bynpm run test:snippets.(error as PubNubError).statuscatch-block ternaries (54 occurrences) withconsole.error(`<operation> failed: ${error}`).PubNubErrorimports.(channel: string) =>parameter annotations inmobile-push.tsandchannel-groups.ts.!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 anduse-cases/files are not touched.Why
Documentation review finding G01 (Platform docs release review, preview 961): the docs embed these
.tsfiles withlanguage="javascript". The extracted regions contained TypeScript-only syntax, so code copied from a "JavaScript" tab failednode --checkbefore any PubNub call.Validation
npm run test:snippetspasses.extractSnippets(src/helper/codeSnippetFetcher.ts) from this branch, and each passesnode --checkas 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.