Skip to content

docs: typescript essential style guide#3389

Open
serkodev wants to merge 21 commits intovuejs:mainfrom
serkodev:docs/essential-style-guide-ts
Open

docs: typescript essential style guide#3389
serkodev wants to merge 21 commits intovuejs:mainfrom
serkodev:docs/essential-style-guide-ts

Conversation

@serkodev
Copy link
Copy Markdown
Member

@serkodev serkodev commented May 7, 2026

Description of Problem

The original Essential Style Guide was designed for JavaScript. In this PR, we will create a Vue Essential Style Guide specifically for TypeScript.

Proposed Solution

  • Please visite /style-guide/rules-essential-ts.html to this guide
  • Updated style guide to TypeScript friendly
  • Added more guides:
    • Access DOM or component instances
    • Avoid destructuring from reactive() directly
    • Watching reactive state
    • Prefer computed over watcher-assigned derived refs
    • Use eager watchers instead of duplicate initial calls

Relared #3370

@netlify
Copy link
Copy Markdown

netlify Bot commented May 7, 2026

Deploy Preview for vuejs ready!

Name Link
🔨 Latest commit 6dc3dfe
🔍 Latest deploy log https://app.netlify.com/projects/vuejs/deploys/69fd9f0ad105300008867b28
😎 Deploy Preview https://deploy-preview-3389--vuejs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Copy Markdown
Member

@ubugeeei ubugeeei left a comment

Choose a reason for hiding this comment

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

I left a few comments for now, mainly about the content itself!

As for the overall structure of the documentation, I still have some doubts, so I’d like to discuss that on Discord instead. (My thoughts aren’t fully formed enough yet to leave comments.)

Comment thread src/style-guide/rules-essential-ts.md Outdated
}>()
```

In Vue 3.4 and earlier, use `withDefaults()` to declare default values for props.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It does depend on the version, but in the Motivation section of the Props Destructure RFC written by Evan, it says:

vuejs/rfcs#502 (comment)

Succinct and native-like syntax for default values and local alias. Big DX improvement over withDefaults().

So I don’t think we need to intentionally mention withDefaults in the style guide.

It became stable in 3.5, but it should have been possible to opt in even before that.

Comment thread src/style-guide/rules-essential-ts.md Outdated
Comment thread src/style-guide/rules-essential-ts.md
Comment thread src/style-guide/rules-essential-ts.md Outdated
```ts
const userId = ref(1)

watch(userId, (id) => loadUser(id), { immediate: true })
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is not the main point, but seeing loadUser may suggest something async.
Combined with watch, it could be interpreted as recommending code that may cause race conditions, so a more motivational example might be better. (For example, opening and closing a dialog)

Previously, there was actually an example like that in the official tutorial, and it caused a bit of discussion.

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