-
-
Notifications
You must be signed in to change notification settings - Fork 413
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
Bug: Instance properties appear in components list #159
Comments
This is expected, because these ones is subtypes of // true
type IsComponent = typeof $emit extends FunctionalComponent<infer _> ? true : false; |
So strange...Is there a workaround? |
@pikax can you take a look to this problem? |
This is a bit tricky since You can validate the functional component like this: type IsComponent<T> = T extends FunctionalComponent<infer P>
? P extends object ? true : false // `P` should be always an object on a functional component, but on emit extends `string`
: false |
@pikax thanks, but that may not handle well, there have more other properties like I'm not sure if this is appropriate, can we make some FunctionalComponent properties not optional to block these function type variables? |
I'm afraid that is not possible because that would break a simple function MyFunctionalComponent(p: { a: 1}) {
return h('div', p.a)
}
type FunctionComponent = IsComponent<typeof MyFunctionalComponent> This changes will affect users using Javascript <template>
<MyComp a="Hello there"></MyComp>
</template>
<script setup>
import { h } from 'vue'
function MyComp(p){
return h('div', p.a)
}
</script>
I reckon this only affects the EDIT: Probably this is a more correct component for your needs type IsComponent<T> = T extends (p: any, ctx?: any) => VNode
? true
: false |
@pikax Unfortunately, widespread impact. 😅 Or can we narrow the FunctionComponent caller return type?
|
Can you give some examples on what's breaking on your side? I can think on ways to improve it, You could also just make a "rule": Only the |
@pikax of course, sorry I should give this first. import { defineComponent, FunctionalComponent } from '@vue/runtime-core';
type ExtractFunctionalComponents<T> = { [K in keyof T as T[K] extends FunctionalComponent<infer _> ? K : never]: T[K] }
const component = defineComponent({
setup() {
return {
foo: () => 123,
bar: () => 'str',
};
}
});
const localComponents: ExtractFunctionalComponents<InstanceType<typeof component>>;
localComponents. // doing auto-complete here should not have `foo`, `bar` This two way also can fix it:
If FunctionComponent is not easy to change, I think I can use the way 1. |
Check this playground
|
I would exclude if the key starts with Something of sorts type ExtractFunctionalComponents<T> = {
[K in keyof T as K extends `$${string}`
? never
: IsFunctionalComponent<T[K]> extends true
? K
: T extends Component
? K
: never]: T[K];
}; |
@pikax Fixed and will update to 0.24.4. |
As the screenshot shows, instance properties shouldn't be showed in components completion list.
The text was updated successfully, but these errors were encountered: