api-typings icon indicating copy to clipboard operation
api-typings copied to clipboard

After passing generics to Component, the methods cannot automatically infer the function types and default to Function

Open anran758 opened this issue 1 year ago • 1 comments

/**
 * 页面中参与渲染的数据
 */
type ComponentData = typeof DEFAULT_DATA

/**
 * 页面中的方法
 */
interface ComponentMethods extends WechatMiniprogram.Component.MethodOption {}

/**
 * 页面的静态实例
 */
interface ComponentInstanceProperty {
  $unbindDialog?: WechatMiniprogram.Component.TrivialInstance
}

Component<ComponentData, {}, ComponentMethods, ComponentInstanceProperty, true>

image image

Does the official source have more recommended practices?

anran758 avatar Aug 06 '24 10:08 anran758

This problem should be difficult to solve, and the best approach might be to avoid creating types for WeChat Mini Program components and pages, instead hacking the Typescript by a typescript plugin.

ayanamists avatar Oct 17 '25 10:10 ayanamists