Giter Club home page Giter Club logo

Comments (4)

fslflame avatar fslflame commented on June 2, 2024

image
image
image

from core.

yyx990803 avatar yyx990803 commented on June 2, 2024

I don't think there is a fix for this, since it's impossible to infer the type passed to expose in the return type of defineComponent in TypeScript.

The workaround is exporting your expose type as a separate interface:

import { defineComponent } from 'vue';

export inteface Exposed {
  getClipDataURL: number
}

export default defineComponent((_, { expose }) => {
  expose({
    getClipDataURL: 1,
  } as Exposed);
  return () => <div>8888</div>;
});

And in other components, import the Exposed interface directly instead of extracting it using InstanceType.

from core.

fslflame avatar fslflame commented on June 2, 2024

我认为这个问题没有解决办法,因为无法推断TypeScriptexpose的返回类型中传递的类型。defineComponent

解决方法是将公开类型导出为单独的接口:

import { defineComponent } from 'vue';

export inteface Exposed {
  getClipDataURL: number
}

export default defineComponent((_, { expose }) => {
  expose({
    getClipDataURL: 1,
  } as Exposed);
  return () => <div>8888</div>;
});

而在其他组件中,Exposed直接导入接口,而不是使用InstanceType.

image
Although this method is feasible, I need to get the component instance through InstanceType, if you specify Exposed then I can not get the component instance ref, is there no two ways?
Because the expose method is part of the component instance

from core.

fslflame avatar fslflame commented on June 2, 2024

image

from core.

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.