0

Using VS Code with Vue 3 and Typescript, is it possible to get autocompletion / suggestions working in the template part of an SFC for things like component props?

As an example, let's say I have a simple component like this named UserComponent:

<template>
    <div>
        {{username}}
    </div>
</template>

<script setup lang="ts">
    interface Props {
        username: string
    }
    const props = defineProps<Props>();
</script>

When using the component and typing in: <UserComponent u - I would expect it to suggest 'username' as a possible prop

I'm using the volar plugin for vs code, and the project was created with Vite.

1 Answer 1

0

Type Support for .vue Imports in TS TypeScript cannot handle type information for .vue imports by default, so we replace the tsc CLI with vue-tsc for type checking. In editors, we need TypeScript Vue Plugin (Volar) to make the TypeScript language service aware of .vue types.

If the standalone TypeScript plugin doesn't feel fast enough to you, Volar has also implemented a Take Over Mode that is more performant. You can enable it by the following steps:

Disable the built-in TypeScript Extension Run Extensions: Show Built-in Extensions from VSCode's command palette Find TypeScript and JavaScript Language Features, right click and select Disable (Workspace) Reload the VSCode window by running Developer: Reload Window from the command palette.

Another thing, for you to get a correct autocomplete use the : before the property example <Component :u

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.