Lack of code completion in Nuxt options API when using typescript

After setting up Nuxtjs with typescript, I noticed that there are no code completions in the template and script as expected based on the title.

Here is the code:

<script lang="ts">
import Vue from 'vue';
import { FeaturedJobs } from '../../types/featuredJobs';

export default Vue.extend({
  data() {
    return {
      transform: 0,
      movedTimes: 0,
      featuredJobs: {} as FeaturedJobs,
    }
  },
  
  mounted() {
    console.log(this.featuredJobs.title) // Here, I anticipate code completion to suggest title and other properties (or anywhere else inside the template same situation)
  }

})

This is my nuxt config build modules where nuxt typescript build is added upon installation:

buildModules: [
    // https://go.nuxtjs.dev/typescript
    '@nuxt/typescript-build',
    // https://go.nuxtjs.dev/tailwindcss
    '@nuxtjs/tailwindcss',
]

These are my package.json dev dependencies:

 "devDependencies": {
   "@nuxt/types": "^2.15.8",
   "@nuxt/typescript-build": "^2.1.0",
   "@nuxtjs/dotenv": "^1.4.1",
   "@nuxtjs/style-resources": "^1.2.1",
   "@nuxtjs/tailwindcss": "^4.2.1",
 }

Furthermore, this is my tsconfig:

{
  "compilerOptions": {
    "target": "ES2018",
    "module": "ESNext",
    "moduleResolution": "Node",
    "lib": [
      "ESNext",
      "ESNext.AsyncIterable",
      "DOM"
    ],
    "esModuleInterop": true,
    "allowJs": true,
    "sourceMap": true,
    "strict": true,
    "noEmit": true,
    "experimentalDecorators": true,
    "baseUrl": ".",
    "paths": {
      "~/*": [
        "./*"
      ],
      "@/*": [
        "./*"
      ]
    },
    "types": [
      "@nuxt/types",
      "@types/node",
      "@nuxtjs/axios",
    ]
  },
  "exclude": [
    "node_modules",
    ".nuxt",
    "dist"
  ]
}

It seems that when I type featuredJobs., completions and suggestions do not come from the FeaturedJobs type.

Answer №1

After some troubleshooting, I was able to discover the solution. It turns out that my setup was correct and everything was functioning properly with the options API. The only thing I needed to do was include a specific line in my settings.json file following the installation of Vetur. Here is the addition necessary for this feature to work in an experimental capacity:

In settings.json:

"vetur.experimental.templateInterpolationService": true

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Update content in the collection

I'm struggling to find a way to update an item in my array. What I aim to achieve is to remove the item before adding it to the list if it already exists. I want to avoid iterating through all items to find the one that needs to be deleted. I attemp ...

The 'log' property cannot be found on the type '{ new (): Console; prototype: Console; }' - error code TS2339

class welcome { constructor(public msg: string){} } var greeting = new welcome('hello Vishal'); Console.log(greeting.msg); I encountered an error at the Console.log statement. The details of the error can be seen in the image attached below. ...

Customizing the file path for the PDF worker: A step-by-step guide

Incorporating the PDF Viewer Component from this source into an Angular 7 project has been a challenge. The documentation clearly states: The default worker is loaded from cdnjs.cloudflare.com. My goal is to load the worker from a local path within my ...

Execute a specialized function with imported modules and specified parameters

Within an npm project, I am looking to execute a custom function with arguments, or ideally provide it as a script in the package.json file like this: npm run custom-function "Hello, World". Currently, I have a file called src/myFunction.ts: import * as e ...

Obtain the precise X and Y coordinates of a <li> element regardless of where the mouse is clicked using Typescript

I'm stuck and could really use some assistance! Hey there, I have a simple question but I seem to be missing a crucial element. Here's my fiddle where I can detect the clicked item but that's as far as I've gotten: http://jsfiddle.ne ...

incongruity discovered during string conversion in HmacSHA256 within Ionic framework

I am facing an issue while trying to create a token in IONIC using the CryptoJS library. The signature generated by the method is different from what I expect. The expected signature is lLJuDJVb4DThZq/yP4fgYOk/14d3piOvlSuWEI/E7po= but the method provides m ...

Is there a way to install @types that are compatible with an outdated version of TypeScript?

I am currently working on a project that relies on packages such as @types/express and @types/body-parser. The problem is, the recent updates to these .d.ts files have introduced generic defaults, which now require TypeScript 2.3 or higher. Unfortunately, ...

Template for typed variable - `ng-template`

How can the parent component correctly identify the type of let-content that is coming from ngTemplateOutletContext? The current usage of {{content.type}} works as expected, but my IDE is showing: unresolved variable type Is there a way to specify the ...

Leveraging @types from custom directories in TypeScript

In our monorepo utilizing Lerna, we have two packages - package a and package b - both containing @types/react. Package A is dependent on Package B, resulting in the following structure: Package A: node_modules/PackageB/node_modules/@types This setup le ...

Uncovering redundant fields in TypeScript and detecting errors through type inference

Encountering an unusual edge case with the TS compiler regarding type inference. Surprisingly, the code snippet below (with commented lines intact) should trigger a compile error, but it doesn't. interface IReturned { theField?: string; } interfa ...

Tips for efficiently inserting large amounts of data using a select subquery

I'm currently using Sequelize in my project and encountering difficulties in converting a simple query into Sequelize syntax. Furthermore, I am also exploring ways to efficiently perform bulk inserts for this particular query. The query in question i ...

Navigating to a specific attribute within a higher-level Component

Within my top-level Component, I have a property that is populated with data from an HTTP source. Here is how it is implemented in a file named app.ts: import {UserData} from './services/user-data/UserData'; Component({ selector: 'app& ...

Is there a way to dynamically retrieve a JSON element in Typescript?

I am using a data grid throughout my application, and currently, I am retrieving the selected rowid with the following code. Here is the HTML snippet: <tbody> <tr *ngFor="let ddata of tableData.data; let i = index" (click)="setClickedRow(ddat ...

What is the best way to send {...rest} properties to a text field in react material?

When using a material textfield inside a wrapper component and passing the remaining props as {...otherprops} in a JavaScript file, everything works fine. However, when attempting to do the same in TypeScript, an error occurs. const TextFieldWrapper = (pro ...

How should dynamic route pages be properly managed in NextJS?

Working on my first project using NextJS, I'm curious about the proper approach to managing dynamic routing. I've set up a http://localhost:3000/trips route that shows a page with a list of cards representing different "trips": https://i.stack. ...

I encountered difficulties rendering a VueJS component after incorporating the Argon Dashboard for Laravel into my project

I have a project that is currently active and all the VueJS components within it are functioning properly. However, after installing the Argon Dashboard for Laravel into my Laravel project, I am having an issue where my VueJs Components are not displayin ...

Steps for configuring mode as 'open' when generating a shadow element with vue-custom-element

Here is the method I used to generate a shadow component Vue.customElement('my-element', MyElement, { shadow: true, shadowCss: mystyles, }); ...

Remove the package from the @types folder within the node_modules directory

I currently have the 'mime' library in my node_modules directory and I am looking to completely remove it from my project, along with its @types files. The reason for this is that the old mime package is not functioning correctly for me, so I wan ...

Struggling to grasp the error: "NDEFReader is not defined" in a Vue3 web application

In the process of developing a vue3 application, I am integrating the NFC Web API to facilitate reading and writing NFC Chips. My project utilizes typescript, vue routing, and pinia for smooth functionality. Everything runs smoothly when the application i ...

What are the best practices for integrating Qt with React in TSX?

While I've figured out how to communicate qt with JS successfully, the challenge arises when trying to use React in TSX for frontend development. The previous solution failed on this front. Backend code: #./main.py import os from PySide6.QtWidgets ...