Typescript incompatibility causing errors with Vue components

I am encountering an issue while using typescript 2.8.3, ts-loader 3.5.0 (as I'm using webpack 2), and vue 2.5.16. The problem arises when attempting to define components in a Single File Component (SFC) like the code snippet below:

<script lang="ts">
  import Vue from 'vue'

  export default Vue.extend({
     name: 'TestComponent',

     props: {
       options: {
          type: Array,
          default: () => [],
       }
     },

     computed: {
       getOptions() {
          return this.options
       },
     }
  })
</script>

The error message received is:

TS2339: Property 'options' does not exist on type 'ComponentOptions, DefaultMethods, DefaultComputed,PropsDefinition'

Below is the content of tsconfig.json:

{
  "compilerOptions": {
    "target": "es5",
    "module": "esnext",
    "strict": true,
    "jsx": "preserve",
    "moduleResolution": "node",
    "allowSyntheticDefaultImports": true,
    "sourceMap": true,
    "noImplicitAny": false,
    "baseUrl": ".",
    "allowJs": true,
    "paths": {
      "test/*": ["test/*"]
    },
    "lib": ["dom", "es2016"],
    "types": ["node", "jest"]
  },
  "include": ["resources/assets/js/**/*.ts", "resources/assets/js/**/*.vue"],
  "exclude": ["node_modules"]
}

Seeking suggestions or solutions to resolve this issue. It seems to work fine if setting "noImplicityThis" to false, however, the autocomplete feature in VSCode does not function correctly in this case.

Answer №1

Managed to get it working by making some changes. Here is the updated tsconfig.json:

{
  "compilerOptions": {
    "target": "es5",
    "module": "esnext",
    "strict": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noImplicitAny": false,
    "jsx": "preserve",
    "moduleResolution": "node",
    "allowSyntheticDefaultImports": true,
    "sourceMap": true,
    "baseUrl": ".",
    "allowJs": true,
    "lib": ["dom", "esnext"],
    "types": ["node", "jest"]
  },
  "include": ["resources/assets/js/**/*.ts", "resources/assets/js/**/*.vue"],
  "exclude": ["node_modules"]
}

Also, made adjustments to vue.d.ts as follows:

declare module '*.vue' {
  import Vue from 'vue'
  export default Vue
}

This solution might come in handy for someone facing a similar issue.

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

What could be preventing me from setting a boolean variable within an Observable?

After retrieving data from the Service, I am attempting to hide a specific div element. Below is the HTML code: <progressbar *ngIf="isLoadingBootStockData" [value]="100" type="default"> </progressba ...

Declaring module public type definitions for NPM in Typescript: A comprehensive guide

I have recently developed a npm package called observe-object-path, which can be found on GitHub at https://github.com/d6u/observe-object-path. This package is written in Typescript and has a build step that compiles it down to ES5 for compatibility with ...

VueJS does not support certain characters in its JavaScript replace function

In my current situation, I am utilizing the replace method in the following manner: <code v-html="'/<try>/'.replace(/(?:\r\n|\r|\n)/g, 'testing')"></code> As I work with a longer string t ...

Steer clear of perpetually spinning loading icons in Vue.js

I am encountering an issue with my Vue.js preloader as it seems to be loading infinitely. I have been thinking about hiding the preloader container when the page is fully loaded using the mounted() method in the App.vue file. However, I am unsure about the ...

What sets my project apart from the rest that makes TypeScript definition files unnecessary?

Utilizing .js libraries in my .ts project works seamlessly, with no issues arising. I have not utilized any *.d.ts files in my project at all. Could someone please explain how this functionality is achievable? ...

pick only one option from each row

I am working on a feature where I have five rows with two checkboxes each generated using a loop and property binding. Currently, clicking on one checkbox selects all elements in the column. However, I want to achieve selection row-wise. Is there a method ...

Multiple invocations of Vue.js function

When running the code and checking the browser console, you may notice that the function "formatName()" is being called multiple times. But why does this happen if the race data isn't being updated? Well, changing the function "amIStarted()" to "retur ...

A guide to efficiently packaging Material UI with a React component in an npm package

Struggling to package Material UI with my React component bundle. The error that keeps popping up reads as follows: × Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the followi ...

initiate changes to the application's style from a component nested within the app

I'm looking to update the background color of the entire page, including the app-nav-bar, when I'm inside a child component. When I navigate away from that component, I want the default style to be restored. Any suggestions on how to achieve this ...

Unable to find solutions for all parameters needed by a CustomComponent within Angular

Whenever I attempt to compile the project for production, an error pops up: There is a problem resolving all parameters for EmployeeComponent in C:/.../src/app/employee/employee.component.ts: (?, ?, ?). Oddly enough, when I run the application, every ...

Converting the first page of the Vuepress README.doc from yaml format to markdown format document

I am struggling to locate instructions on customizing the homepage of Vuepress. While I appreciate its layout, the .yaml format is preventing me from adding links. Is there a way to include links? Or even better, can the page be converted to markdown whi ...

Using useState as props in typescript

Let's imagine a situation where I have a main component with two smaller components: const MainComponent = () => { const [myValue, setMyValue] = useState(false) return ( <> <ChildComponent1 value={myValue} setValue={set ...

Controlling a generic interface's acceptance of certain data types in typescript: a guide

Is there a way to restrict a generic interface from accepting specific data types in TypeScript? I understand that I can define acceptable data types for a generic interface in TypeScript. interface exampleInterface<T = void | any>; But what if I w ...

react-i18next - The function call does not match any overload when the specified type is `string`

I am currently utilizing react-i18next in conjunction with React and TypeScript. Interestingly, when I attempt to load a property using a string literal and type inference, everything works seamlessly. However, once I specify the type as string, an error i ...

A guide on connecting multiple select components to a unified Angular 6+ reactive form without triggering redundant updates

I am facing an issue where I need to connect multiple input components to a single angular reactive form, but encounter two main obstacles: By default, only the form in which user input occurs gets updated If I use [(ngModel)] it does work, but it trigge ...

How can a debounce function be customized to work on multiple instances of the same Vue.js component autonomously?

I am encountering an issue with two Vue components that each have a "save to disk" call triggered on every change of data. These components utilize a mixin to load the data, and they save into separate files in order to function independently (each trigger ...

Retrieve data from a web api at regular intervals using Angular observables and subscription

My Launch method is designed to start an engine by taking parameters and returning the instance name once started. After that, I need to periodically query another service every 2 seconds to check if the status has changed to either "Succeeded" or "Faile ...

Using ASP.NET MVC to map FormData with an array to a model class

I am currently facing an issue with mapping a list of objects in a FormData to my ASP.NET MVC Model class at the controller. I have successfully sent the FormData over to the server-side, but I am unable to bind any value. Can someone provide guidance on h ...

Utilizing Vuex, is it possible to filter an array by incorporating another array in a Javascript view?

When using VueX, I am attempting to filter my "ListJobs" array based on the currentTag. Essentially, I want to return elements that match any of the values in the currentTag array with the rows role, level, languages, and tools. state: [ listJobs: ...

Getting the Correct Nested Type in TypeScript Conditional Types for Iterables

In my quest to create a type called GoodNestedIterableType, I aim to transform something from Iterable<Iterable<A>> to just A. To illustrate, let's consider the following code snippet: const arr = [ [1, 2, 3], [4, 5, 6], ] type GoodN ...