language-tools icon indicating copy to clipboard operation
language-tools copied to clipboard

[bug] experimentalUseElementAccessInTemplate disables type check for used properties

Open orimay opened this issue 3 months ago • 6 comments

experimentalUseElementAccessInTemplate option makes protected field errors (ts-plugin(2339)) go away, but at the same time, it stops bothering with variables used in the template:

<script lang="ts">
  @Component({}) export default class ... {
    protected config = { whatever: true };
    protected messages = {
      first: 'Success!'
    };
  }
</script>

<template>
  <MyComponent
    :config="cornfig.whatever"
    :message="messages.first"
  />
</template>

It won't complain about cornfig and cornfig.whatever will be of type any. At the same time, if I hover messages in template, it won't hint the type, but it will hint the type for messages.first (string). Is it possible to have properties checked and have their type provided? If I disable experimentalUseElementAccessInTemplate, the ts-plugin(2339) error comes back, but so do the type checks. It will then complain that cornfig does not exist and will show type for messages.

Thank you!

orimay avatar Mar 19 '24 10:03 orimay

Actually, even messages.boo won't give an error of a non-existant boo property. It will have type of any

orimay avatar Mar 19 '24 12:03 orimay

Where does the Component decorator come from?

so1ve avatar Mar 22 '24 05:03 so1ve

import Component from 'vue-class-component';

orimay avatar Mar 29 '24 14:03 orimay

I guess this is because using index signatures to classes is allowed in typescript:

class a {}

a['foo'] // No errors

so1ve avatar Apr 08 '24 03:04 so1ve

But it should error out on unknown property cornfig and should show type of messages

orimay avatar Apr 08 '24 10:04 orimay

We read properties directly from the class, so Class.xxx will report an error, but Class['xxx'] doesn't. We need to find a workaround

so1ve avatar Apr 08 '24 13:04 so1ve