Subscribe on changes!

Add option to enable Typescript by default in <script>

avatar
Nov 18th 2022

What problem does this feature solve?

If you have fully Typescript project it doesn't make sense to write <script lang="ts"> all the time. It would be nice to have an option to enable Typescript by default.

What does the proposed API look like?

compileScript(src, {
  defaultLang: 'ts'
})
avatar
Nov 21st 2022

Sounds like editors and IDEs could potentially lose out on syntax highlighting features. For example, treesitter and its vue parser would need to know about this option.

avatar
Nov 22nd 2022

Yeah. Once it gets supported in Vue compiler, then ESLint, Volar, and other tools have to support this feature as well.

avatar
Dec 29th 2022

Thank you for your proposal, but I hope avoid adding this feature, I think it makes sense to add lang explicitly.

  • This feature needs to be followed by all downstream tools, we should try our best to avoid this, because if some IDE can't support it, we can't control this. Volar is easy to support for IntelliSense, but Syntax Highlight is not, and VSCode doesn't actually support configurable Syntax Highlight behavior. Furthermore, the Syntax Highlight behavior needs to be implemented individually by each IDE, instead of directly taking effect in all downstream IDEs when Volar is implemented.
  • If it is implemented and this feature becomes popular, lang less script block not necessarily javascript will be an extra mental burden, which is no problem for a project developed by one person, but I think less mental burden for the community is very important.
avatar
Dec 29th 2022

Also, if you have to type <script lang="ts" setup> every time you create a component you are probably doing something wrong. You can set up snippets that generates barebone vue skeletons, works with all IDEs.

avatar
Dec 30th 2022

My point in this proposal is more about cleaner component look without the repetitive lang=“ts” in each file. For sure, most of devs use snippets and this is even not a problem, it’s just “don’t repeat it” feature if you have 100% TS codebase.

avatar
Oct 19th 2023

Yeah. Once it gets supported in Vue compiler, then ESLint, Volar, and other tools have to support this feature as well.

I don't understand the argument, this can be said about any feature in any framework, should we stop adding them because of it?

Sounds like editors and IDEs could potentially lose out on syntax highlighting features. For example, treesitter and its vue parser would need to know about this option.

Why should they lose anything if IDEs and editors can freely analyze compileScript configs

compileScript(src, {
  defaultLang: 'ts'
})

this is not something forbidden for analyzation, right?