Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot find name XXX when using TypeScript component with complex prop type #2826

Closed
4 tasks done
KodrAus opened this issue Mar 30, 2021 · 2 comments
Closed
4 tasks done

Comments

@KodrAus
Copy link

KodrAus commented Mar 30, 2021

  • I have searched through existing issues
  • I have read through docs
  • I have read FAQ
  • I have tried restarting VS Code or running Vetur: Restart VLS

Info

  • Platform: Windows 10
  • Vetur version: vti 0.1.1
  • VS Code version: N/A

Problem

The code emitted behind vetur will reference the types of complex properties without importing them first. I'm not sure if this is really a vetur issue or something upstream.

For example, if we have a complex.ts:

export interface Complex {
    value: string
}

A WithComplexProps.vue:

<template>
  <div>
    {{ data.value }}
  </div>
</template>

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

import { Complex } from './complex'

export default Vue.extend({
  props: {
      data: {
          type: Object as PropType<Complex>,
          required: true
      }
  }
})
</script>

A Test.vue:

<template>
  <div>
    <with-complex-props :data="complex" />
  </div>
</template>

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

import WithComplexProps from './WithComplexProps.vue'

export default Vue.extend({
  components: {
    WithComplexProps
  },
  data () {
    return {
      complex: {
        value: 'hello'
      }
    }
  }
})
</script>

Then Test.vue will produce the following virtual file:

====================
Virtual content of path\Test.vue.template
Hover, semantic diagnostics, jump to definition and find references are run on this file.
====================

import __vlsComponent from "./Test.vue";
import { __vlsRenderHelper, __vlsComponentHelper, __vlsIterationHelper, __vlsComponentData } from "vue-editor-bridge";
__vlsRenderHelper(__vlsComponent, function () { __vlsComponentHelper(this, "div", { props: {}, on: {}, directives: [] }, [__vlsComponentHelper__with_complex_props(this, "with-complex-props", { props: { "data": this.complex }, on: {}, directives: [] }, [])]); });

interface __vlsComponentData__with_complex_props<T> extends __vlsComponentData<T> {
  props: { data: Complex, [other: string]: any }
  on: {  } & { [K in keyof T]?: ($event: T[K]) => any; }
}
declare const __vlsComponentHelper__with_complex_props: {
  <T>(
    vm: T,
    tag: string,
    data: __vlsComponentData__with_complex_props<Record<string, any>> & ThisType<T>,
    children: any[]
  ): any
}

====================
SourceMap
from: path\src\Test.vue
to  : path\src\Test.vue.template
[VueFileStart, VueFileEnd, VueFileText] => [TSVirtualFileStart, TSVirtualFileEnd, TSVirtualFileText]
====================

[15, 18, div] => [246, 251, props]
[26, 44, with-complex-props] => [355, 360, props]
[46, 50, data] => [364, 370, "data"]
[52, 59, complex] => [372, 384, this.complex]

with this problematic snippet:

interface __vlsComponentData__with_complex_props<T> extends __vlsComponentData<T> {
  props: { data: Complex, [other: string]: any }
  on: {  } & { [K in keyof T]?: ($event: T[K]) => any; }
}

that produces this output from vti:

====================================
Getting Vetur diagnostics
Loading Vetur in current directory: path\veturpack
Vetur initialized
====================================

Getting diagnostics from:  [ 'src/Test.vue', 'src/WithComplexProps.vue' ]

[INFO ] Find node_modules paths in path - 148ms
[INFO ] Loaded bundled [email protected].
[INFO ] Loaded bundled prettier.
[INFO ] Loaded bundled @starptech/prettyhtml.
[INFO ] Loaded bundled prettier-eslint.
[INFO ] Loaded bundled prettier-tslint.
[INFO ] Loaded bundled stylus-supremacy.
[INFO ] Loaded bundled @prettier/plugin-pug.
File : fpath\Test.vue:1:1
Error: Cannot find name 'Complex'.
> 1 | <template>
    | ^
  2 |   <div>
  3 |     <with-complex-props :data="complex" />
  4 |   </div>

====================================
VTI found 1 error

Reproducible Case

https://github.com/KodrAus/vti-repro

@KodrAus
Copy link
Author

KodrAus commented Mar 30, 2021

This actually appears to be a dupe of: #2668

@yoyo930021
Copy link
Member

Duplicate of #2668

@yoyo930021 yoyo930021 marked this as a duplicate of #2668 Apr 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants