Skip to content

fix: enable types in JS code blocks #1398

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

fix: enable types in JS code blocks #1398

wants to merge 3 commits into from

Conversation

eltigerchino
Copy link
Member

@eltigerchino eltigerchino commented Jun 27, 2025

fixes #999

This PR makes the following changes to fix types in the docs:

  • correctly generate types for JS code blocks by properly appending injected content, separating them with filenames.
  • makes additional types available on hover by installing the packages so that TypeScript can resolve their type info
  • cleans up some of the injected content that's duplicated or unused

This PR shouldn't be merged until all the required docs have their TypeScript error markers updated.

Before submitting the PR, please make sure you do the following

  • It's really useful if your PR references an issue where it is discussed ahead of time.
  • Prefix your PR title with feat:, fix:, chore:, or docs:.
  • This message body should clearly illustrate what problems it solves.

Copy link

vercel bot commented Jun 27, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
svelte-dev ❌ Failed (Inspect) Jun 27, 2025 4:43pm

@@ -7,11 +7,7 @@ export const render_content = (
) => {
return render_content_markdown(filename, body, options, (filename, source) => {
// TODO these are copied from Svelte and SvelteKit - adjust for new filenames
const injected = [];

if (/(svelte)/.test(source) || filename.includes('typescript')) {
Copy link
Member Author

Choose a reason for hiding this comment

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

This was previously always being injected for any file that mentions 'svelte'. Instead, we can just reference the Svelte types in the Twoslash typescript options

if (
source.includes('$app/') ||
source.includes('$service-worker') ||
source.includes('@sveltejs/kit/')
Copy link
Member Author

Choose a reason for hiding this comment

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

We don't need to check for @sveltejs/kit/* because Twoslash can resolve those itself

@@ -71,10 +69,6 @@ export const render_content = (
injected.push('// @errors: 7006 7031');
}

if (filename.endsWith('10-configuration.md')) {
Copy link
Member Author

Choose a reason for hiding this comment

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

There is no such file in the docs

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.

Types do not appear on hover for JSDoc annotated items
1 participant