0

There are many examples/solutions to this particular error, but in my case I think it must have a different, underlying cause. Possibly configuration related.

The code is

export default {
  data() {
    return {
      asyncDataStatus_ready: false,
    };
  },

  methods: {
    asyncDataStatus_fetched():any {
      this.asyncDataStatus_ready = true;
      this.$emit('ready');
    },
  },
};

The errors are

Property 'asyncDataStatus_ready' does not exist on type '{ asyncDataStatus_fetched(): any; }'. Did you mean 'asyncDataStatus_fetched'?ts(2551)

and

Property '$emit' does not exist on type '{ asyncDataStatus_fetched(): any; }'.ts(2339)

So it seems to me as if Typescript thinks these are properties of asyncDataStatus_fetched, which they are not. Wondering if it has to do with 'this', but not sure what else to try. Thinking there must be another way for methods to access data in a .ts. file vs a .vue file.

1 Answer 1

1

The lexical scope of this is not bound to the component but the function, use a fat arrow:

methods: {
    asyncDataStatus_fetched: () => {
}
Sign up to request clarification or add additional context in comments.

2 Comments

Although that does bypass this particular error, it may not be the proper solution in this case, as it brings about 2 other errors: 1. Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature. 2. The containing arrow function captures the global value of 'this'
@Khepf Your question is answered. These are new questions you have. Your ultimate question is how to use typescript with vue single file components.

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.