-
Notifications
You must be signed in to change notification settings - Fork 344
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
createComponent in TypeScript not inherit from Vue ComponentOptions #63
Comments
ps: After more research out package, i found that in
import Vue, { VueConstructor } from 'vue';
import { SetupFunction, SetupContext } from './ts-api';
import { Wrapper } from './wrappers';
declare module 'vue/types/options' {
interface ComponentOptions<V extends Vue> {
setup?: SetupFunction<{}, {}>;
}
}
.... I dont know why we had define
// ComponentOptions is declared in types/options.d.ts
declare module 'vue/types/options' {
interface ComponentOptions<V extends Vue> {
myOption?: string;
}
} import Vue, { ComponentOptions } from 'vue';
import { createComponent } from 'vue-function-api';
import { ComponentPropsOptions } from 'vue-function-api/dist/ts-api/componentProps';
export default createComponent({
setup(props, context) {
return {};
},
myOption: 'yes it work'
} as ComponentOptions<Vue>); Hope this will help we fix issue faster. Thank again for your good stuff before new age of Vue 3 💃 |
If you use import { ComponentOptions } from 'vue-function-api/dist/ts-api/component'
declare module 'vue-function-api/dist/ts-api/component' {
interface ComponentOptions {
myOption?: string
}
} |
It seems that not being an instance of If the component doesn't have a |
i have update version of @PatrykWalach : import { ComponentOptions } from 'vue-function-api/dist/ts-api/component';
import Vue, { ComponentOptions as VueComponentOptions } from 'vue';
declare module 'vue-function-api/dist/ts-api/component' {
interface ComponentOptions extends VueComponentOptions<Vue> {}
} like this we will have all properties typesafe from vue constructor 2.x. and still allow Infer prop parameter of in case you dont want input all properties, can do: import { ComponentOptions } from 'vue-function-api/dist/ts-api/component';
import Vue, { ComponentOptions as VueComponentOptions } from 'vue';
declare module 'vue-function-api/dist/ts-api/component' {
interface ComponentOptions extends Pick<VueComponentOptions<Vue>, 'name' | 'components' |....> {
}
} |
Shouldn't it be import Vue, { ComponentOptions as VueComponentOptions } from 'vue';
declare module 'vue-function-api/dist/ts-api/component' {
interface ComponentOptions
extends Exclude<VueComponentOptions<Vue>, 'props'> {}
} ? Otherwise you're overwriting |
@IlCallo hm... this depend on how many property you need ship from vue 2.x into vue-function-api typechecking. Actually i not need all of them , only need |
Yeah, I'm talking about the first mode you used, which adds everything.
Also, |
@IlCallo i see, you right my first trick will raise issue with typechecking, in this case my only way i think good is manual transfer properties from Vue 2.x we really need into Vue3.x type: import { ComponentOptions } from 'vue-function-api/dist/ts-api/component';
import Vue, { ComponentOptions as VueComponentOptions } from 'vue';
declare module 'vue-function-api/dist/ts-api/component' {
type d = VueComponentOptions<Vue>;
interface ComponentOptions {
name?: d['name'];
components?: d['components'];
methods?: d['methods'];
}
} This is my also about question what the import api component line doing: I think it is for reference to this is file import Vue, { ComponentOptions } from 'vue';
import { VeeValidateComponentOptions } from 'vee-validate';
declare module 'vue/types/vue' {
// Global properties can be declared
// on the `VueConstructor` interface
interface VueConstructor {}
}
// ComponentOptions is declared in types/options.d.ts
declare module 'vue/types/options' {
interface ComponentOptions<V extends Vue> {
$_veeValidate?: VeeValidateComponentOptions;
}
} my project i store both 2 d.ts file, one for extend for custom option, |
You actually don't need it. You are defining in the
Will check it next week, tomorrow I go on vacation :P |
vue-router error. Actually the fix to this is pretty simple, just they haven't add it to the VueCLI, you need to add a type into the Route Array, you can check this: |
from Vue 2.x , when use with TypeScript we always write shims file
d.ts
whichs support static type property used inside vue component object.ex: in Nuxt, each component use as
page
need defined$options.layout = 'layout name'
like this:To typesafe this custom property, they provide
d.ts
:For now
vue-function-api
provide functioncreateComponent
to help TS's developer can inherit typesafe from package. Viewd.ts
file i see function defined:This not inherit from Vue ComponentOptions , so we lost all typesafe from shims file.
A modify d.ts code will help a lot to inherit from Vue 2.x setup env .
Thankyou!
The text was updated successfully, but these errors were encountered: