Giter Club home page Giter Club logo

Comments (11)

TrungRueta avatar TrungRueta commented on April 28, 2024 3

If you use as assignment wrapping the code in createComponent does nothing.
If you want to use createComponent you have to extend the interface used by the function as an argument.

import { ComponentOptions } from 'vue-function-api/dist/ts-api/component'

declare module 'vue-function-api/dist/ts-api/component' {
  interface ComponentOptions {
    myOption?: string
  }
}

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 setup.

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' |....> {
  }
}

from composition-api.

PatrykWalach avatar PatrykWalach commented on April 28, 2024 2

If you use as assignment wrapping the code in createComponent does nothing.
If you want to use createComponent you have to extend the interface used by the function as an argument.

import { ComponentOptions } from 'vue-function-api/dist/ts-api/component'

declare module 'vue-function-api/dist/ts-api/component' {
  interface ComponentOptions {
    myOption?: string
  }
}

from composition-api.

TrungRueta avatar TrungRueta commented on April 28, 2024 1

ps: After more research out package, i found that in index.d.ts file we had modify Vue Component Options really;

vue-function-api/dist/index.d.ts:

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 setup function into Vue Component Options but not use it when define createComponent function, but use custom interface which lack of inherit from Vue. But from this point i had work around for component:

shims-vue.d.ts

// 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 💃

from composition-api.

hzgotb avatar hzgotb commented on April 28, 2024 1

WX20190821-220125@2x

vue-router error.
import SignIn from './views/SignIn.vue';

export default new Router({
  mode: 'history',
  base: process.env.BASE_URL,
  routes: [
    {
      path: '/sign-in',
      name: 'SignIn',
      component: SignIn,   // use createComponent
    },
  ],
});

image

from composition-api.

IlCallo avatar IlCallo commented on April 28, 2024

It seems that not being an instance of Vue anymore, but a VueProxy instead, this change broke most testing methods (eg. shallowMount(), mount()) as they cannot infer wrapper.vm type.
This results into either a TS error when mounting or the vm type to be never, making it useless.

If the component doesn't have a props property, its instance will be wrongly inferred as a FunctionalComponent and TypeScript will fire off an error asking for the missing functional property.

from composition-api.

IlCallo avatar IlCallo commented on April 28, 2024

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 props typings with their v2 counterparts.

from composition-api.

TrungRueta avatar TrungRueta commented on April 28, 2024

@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 name, components to make Vue2.x system work.

from composition-api.

IlCallo avatar IlCallo commented on April 28, 2024

Yeah, I'm talking about the first mode you used, which adds everything.
Even doing as I did (leaving off props from original type) rises a warning in TS I actually don't understand.

Interface 'ComponentOptions<PropsOptions, RawBindings, Props>' incorrectly extends interface 'ComponentOptions<Vue, DefaultData<Vue>, DefaultMethods<Vue>, DefaultComputed, PropsDefinition<Record<string, any>>, Record<string, any>>'.
  Types of property 'props' are incompatible.
    Type 'PropsOptions | undefined' is not assignable to type 'string[] | RecordPropsDefinition<Record<string, any>> | undefined'.
      Type 'PropsOptions' is not assignable to type 'string[] | RecordPropsDefinition<Record<string, any>> | undefined'.
        Type 'PropsOptions' is not assignable to type 'string[]'.

Also, import { ComponentOptions } from 'vue-function-api/dist/ts-api/component'; doesn't appear to do anything, what's that import for?

from composition-api.

TrungRueta avatar TrungRueta commented on April 28, 2024

@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 d.ts file , i only need methods , components, name for basic vue component.

also about question what the import api component line doing: I think it is for reference to ComponentOptions of vue-function-api, no ?

this is file d.ts to extend ComponentOptions of vue , i pick from Vue TS document and Nuxt project:

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, buefy type etc etc into v2.x Vue ComponentOptions, like normal, and second file is extends what property i want into vue-function-api's ComponentOptions . with my last suggest trick above i nolonger meet typechecking fails anymore. can you try .

from composition-api.

IlCallo avatar IlCallo commented on April 28, 2024

also about question what the import api component line doing: I think it is for reference to ComponentOptions of vue-function-api, no ?

You actually don't need it. You are defining in the vue-function-api namespace a new interface with the same name of the old one and they are merged because of TypeScript interface merging capabilities. Importing it won't do anything because you are not actually referencing it.

with my last suggest trick above i nolonger meet typechecking fails anymore. can you try .

Will check it next week, tomorrow I go on vacation :P
I already solved using your second way of just selecting the needed properties, anyway. I needed just name and components too.

from composition-api.

manuelojeda avatar manuelojeda commented on April 28, 2024
WX20190821-220125@2x vue-router error.
import SignIn from './views/SignIn.vue';

export default new Router({
  mode: 'history',
  base: process.env.BASE_URL,
  routes: [
    {
      path: '/sign-in',
      name: 'SignIn',
      component: SignIn,   // use createComponent
    },
  ],
});

image

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:
vuejs/vue-cli#4805

from composition-api.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.