Comments (8)
hi @Hope410, you already can use PropType form @vue/composition-api
module. I'm not sure which part you are missing, so here is a example:
import { defineComponent, PropType } from '@vue/composition-api'
export default defineComponent({
props: {
foo: Object as PropType<AnyTypeYouWant>
}
})
from language-tools.
hi @Hope410, you already can use PropType form @vue/composition-api module. I'm not sure which part you are missing, so here is a example:
I use PropType from vue import and don't use defineComponent from @vue/composition-api.
from language-tools.
@dynamite-ready The type inference provided by Vue.extend
is very limited. For example, cross-component props type-checking is not supported.
from language-tools.
have you try defineComponent? as I know PropType only work for defineComponent, but not Vue.extend.
from language-tools.
as I know PropType only work for defineComponent, but not Vue.extend.
PropType from vue works as well.
So, i used defineComponent, and prop type infered correctly, thanks. But could you add support of Vue.extend? It would be very helpful for vue2 + typescript users, i think most of them use Vue.extend
from language-tools.
We need $props
types for element props type-checking, PropType from vue
can only work for this
type inside Vue.extend({ ... })
, but not working for $props
:
import Vue, { PropType } from 'vue';
const A = Vue.extend({
props: {
foo: String,
},
mounted() {
this.foo // string
}
});
const a = new A();
a.$props.foo // any
check the source code, Vue.extend
seem do nothing for $props
types infer: https://github.com/vuejs/vue/blob/5255841aaff441d275122b4abfb099b881de7cb5/types/vue.d.ts#L34
I'm not sure dose they have plan to improve Vue.extend
types or not, anyway this is upstream problem.
from language-tools.
I understood, anyway, thank you!
from language-tools.
Somehow, Prop checking worked for me in Vue 2 (Nuxt), while using Vue.extends({})
:
The docs for Volar say this shouldn't work, no?
This seems great for now, but can I always count on this behaviour?
from language-tools.
Related Issues (20)
- 插件快点更新回之前的 HOT 4
- 希望保留volar定位样式的功能 HOT 2
- 如果vscode中,代码提示很慢,可以通过以下方式解决。 HOT 6
- The folded area will automatically expand when typing codes HOT 4
- 在过去 5 分钟内,JS/TS 语言服务崩溃了 5 次。 这可能是由以下其中一个扩展提供的插件引起的: Vue.volar 请在针对 VS Code 提交问题之前尝试禁用这些扩展。 HOT 5
- Issues after upgrade to v2 HOT 4
- The ts type prompt in all .vue files is incorrect HOT 6
- Please stop the unconstructive rants
- The TypeScript Vue Plugin (Volar) HOT 1
- Property 'XXX' does not exist on type 'Ref<YYY>'.ts-plugin(2339) HOT 4
- TypeScript server crashes ad infinitum when using v2 and above HOT 5
- 类型“Omit<{ "XXXX": ComponentPublicInstanceConstructor<{ $: ComponentInternalInstance; $data: {}; $props: Partial<{}> & Omit<Readonly<ExtractPropTypes<{}>> & VNodeProps & AllowedComponentProps & ComponentCustomProps, never>; ... 10 more ...; $watch(source: string | Function, cb: Function, options?: WatchOptio...”上不存在属性“AButton”。ts-plugin(2339) HOT 6
- V.2.0.6 - Long wait time to see vue-tsc output HOT 2
- Return deletes the line above... in v2, but ok in v1.8.27 HOT 3
- ts-plugin error HOT 3
- v2: Linting issue at "emits" for defineComponent with TypeScript
- vue-tsc create unexpect declaration file from js HOT 1
- Incorrect Union Types Suggestions in Vue + TypeScript Project in VSCode HOT 1
- Language server critical regression from 2.0.5 to 2.0.6 HOT 6
- TS Language Server Crashes HOT 11
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from language-tools.