0

VueJS 2.5 is out, and I was waiting for TypeScript enhancements, but after upgrading required dependencies, I really can't see any enhancements.

From what i've read this should display a type error, because msg is a number

<template>
  <div>
    <h1>{{ msg }}</h1>
  </div>
</template>

<script lang="ts">
  export default {
    data: function () {
      return {
        msg: 1
      }
    },
    methods: {
      test: function (): number {
        return this.msg.indexOf('App')
      }
    }
  }
</script>

But it actually gives no error, exactly like in previous version. Any clue ? Where are the new TypeScript features ?

3 Answers 3

1

It is important to have a tsconfig.json and set "strict" to true. See https://v2.vuejs.org/v2/guide/typescript.html#Recommended-Configuration

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

1 Comment

"strict": true do the job, but it also check other possible errors I don't want to check. I'll stick to "noImplicitThis": true.
0
export default Vue.extend({
    // data
    // methods
})

Type inference for this in Vue component could only happen when using canonical Vue API.

1 Comment

Sorry, but it doesn't work any better with this notification.
0

noImplicitThis must be set to true in tsconfig.json. allowSyntheticDefaultImports option can also be removed.

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.