Giter VIP home page Giter VIP logo

api-typings's People

Contributors

baranwang avatar chs97 avatar dependabot[bot] avatar garfield550 avatar megasu avatar mister-hope avatar mlzzen avatar okxiaoliang4 avatar sgly avatar tidyzq avatar tttrz avatar wechat-miniprogram-admin avatar xieyhn avatar yangmingshan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

api-typings's Issues

[component] rewrite with better thistype

重写了 component 定义,除了behaviors 没有测试,其他常用Component的特性和类型绑定基本都支持了:

  • properties 类型关联和自动推断
  • observer this 绑定
  • data 绑定
  • setData 类型推断
  • methods 中访问 this data
  • lifetimes 中访问data和methods
  • fix triggerEvent

示例:

Component({
    data: {
        x: 'xx',
        b: {
            nn: 1,
            bb: false
        }
    },
    properties: {
        yy: String, // string 类型
        lll: { // number 类型
            value: 124,
            type: Number,
            observer(newVal: number, oldVal: number) {
                const x = newVal + oldVal + this.data.b.nn; //observer this 绑定
                this.KKKK();
                this.setData({
                    x: 'y',
                    yy: 'y'
                })
            }
        }
    },
    lifetimes: {
        ready() {
            this.KKKK() // lifetimes 调用 methods
            //$ExpectError
            // this.data.x=1; // data 只读
            this.properties.lll; // 访问 properties (number)
            this.data;
            this.setData({
                lll: 12, // setdata
                'uu.x': ''
            }, (d) => { // callback 参数
                d.yy;
                d.b.bb;
            })
        }
    },
    methods: {
        KKKK() {
            this.mmm() //函数调用
        },
        mmm() {
            this.dataset.x; //dataset
            this.data.x; 
        },
        onTest(e:event.Base){
            this.triggerEvent(e.type); // 调用 triggerEvent
        }
    }

update and release here

https://github.com/MS-DG/api-typings/releases/tag/v2.7.0

onGyroscopeChange回调参数有问题

    /** [wx.onGyroscopeChange(function callback)](https://developers.weixin.qq.com/miniprogram/dev/api/device/gyroscope/wx.onGyroscopeChange.html)
     *
     * 监听陀螺仪数据变化事件。频率根据 [wx.startGyroscope()](https://developers.weixin.qq.com/miniprogram/dev/api/device/gyroscope/wx.startGyroscope.html) 的 interval 参数。可以使用 [wx.stopGyroscope()](https://developers.weixin.qq.com/miniprogram/dev/api/device/gyroscope/wx.stopGyroscope.html) 停止监听。
     *
     * 最低基础库: `2.3.0` */
    onGyroscopeChange(
      /** 陀螺仪数据变化事件的回调函数 */
      callback: OnGyroscopeChangeCallback,
    ): void;
  type OnGyroscopeChangeCallback = (
    result: OnGyroscopeChangeCallbackResult,
  ) => void;
  interface OnGyroscopeChangeCallbackResult {
    res: Result;
  }
 interface Result {
    /** x 轴的角速度 */
    x: number;
    /** y 轴的角速度 */
    y: number;
    /** z 轴的角速度 */
    z: number;
  }

上面写的是错的,应该去掉result直接将OnGyroscopeChangeCallbackResult改为

  interface OnGyroscopeChangeCallbackResult {
      /** x 轴的角速度 */
      x: number;
      /** y 轴的角速度 */
      y: number;
      /** z 轴的角速度 */
      z: number;
  }

  interface OnGyroscopeChangeCallbackResult extends Result {  }

[component] properties

  1. 不支持缩写形式?
{
  properties:{
    key:Boolean // 直接指明类型
  }
}
  1. optionalTypes 为可选属性 ?

optionalTypes: PropertyType[];

  1. properties 和 data 在BaseComponent中声明了,不用再在继承的 WxComponent重新定义了

/** 组件数据,**包括内部数据和属性值** */
data: object;
/** 组件数据,**包括内部数据和属性值**(与 `data` 一致) */
properties: {
[propertyName: string]: PropertyOption;
};

declare interface BaseComponent extends ComponentLifetimes {
/** 组件的对外属性,是属性名到属性设置的映射表 */
properties?: {
[propertyName: string]: PropertyOption;
};
/** 组件的内部数据,和 `properties` 一同用于组件的模板渲染 */
data?: object;

ReadFileOption的encoding定义

encoding?:
| 'ascii'
| 'base64'
| 'binary'
| 'hex'
| 'ucs2/ucs-2/utf16le/utf-16le'
| 'utf-8/utf8'
| 'latin1';

这里的 | 'utf-8/utf8' 应该改为 | 'utf-8' | 'utf8' ,'ucs2/ucs-2/utf16le/utf-16le'也是一样

Missing `wx.arrayBufferToBase64` and `wx.base64ToArrayBuffer` typings.

Missing wx.arrayBufferToBase64 and wx.base64ToArrayBuffer typings.

2017.03.28
A 新增 mac 版开发工具支持蓝牙调试
A 新增 wx.reLaunch wx.chooseAddress wx.openSetting wx.getClipboardData wx.setClipboardData wx.arrayBufferToBase64 wx.base64ToArrayBuffer wx.showLoading wx.hideLoading wx.startAccelerometer wx.stopAccelerometer wx.onNetworkStatusChange wx.hideShareMenu wx.showShareMenu CanvasContext.setTextAlign 等 API 的调试支持

https://developers.weixin.qq.com/miniprogram/dev/devtools/uplog.html#20170328

Cannot augment module 'wx' with value exports

报错如下:

node_modules/miniprogram-api-typings/types/wx/lib.wx.cloud.d.ts(202,19): error TS2649: Cannot augment module 'wx' with value exports because it resolves to a non-module entity

版本:
^2.6.5-1

wx.reportAnalytics有问题

应该是文档表达的不好。

在案例中:

wx.reportAnalytics('purchase', {
  price: 120,
  color: 'red'
})

很明显,data应该是如下的的形式:

  /** 上报的自定义数据。 */
  interface Data {
    /** 配置中的字段名: 上报的数据 */
    [key: string]: any;
  }

而不是根据文档生成的

  /** 上报的自定义数据。 */
  interface Data {
    /** 配置中的字段名 */
    key: string;
    /** 上报的数据 */
    value: any;
  }

根据文档中生成的这种写法实际是无效的....就是
{
key:value
}
的写法

[Page]this.setData

Page 里this.setData什么时候才能支持去掉this.setData!()中的感叹号

wx canvasGetImageData 成功回调参数类型错误

lib.wx.api.d.ts#L11258
type CanvasGetImageDataSuccessCallback应该是三个参数
width: number,
height: number,
data: Uint8ClampedArray

而不是
result: CanvasGetImageDataSuccessCallbackResult,
data: Uint8ClampedArray,

组件的声明文件有问题

不是我说,compoenent的定义也太糊弄了吧?各种报错。可不可以用心做一份。

declare interface BaseComponent extends ComponentLifetimes {
  /** 组件的对外属性,是属性名到属性设置的映射表 */
  properties?: {
    [propertyName: string]: PropertyOption;
  };
  /** 组件的内部数据,和 `properties` 一同用于组件的模板渲染 */
  data?: object;
.  ..

此处写法有问题,对于属性,官网是允许简写的。

Component({
  properties: {
    myProperty: { // 属性名
      type: String,
      value: ''
    },
    myProperty2: String // 简化的定义方式
  },
  ...

另外,由于property在组件初始化的时候会变成data的引用,他们两个本质上是一个对象(详见官方文档),所以访问的时候会出现Property 'xx' does not exist on type 'object'.

修改建议:

declare interface BaseComponent extends ComponentLifetimes {
  /** 组件的对外属性,是属性名到属性设置的映射表 */
  properties?: {
    [propertyName: string]: PropertyOption | Boolean | String | Number | Array | Object;
  };
  /** 组件的内部数据,和 `properties` 一同用于组件的模板渲染 */
  data?: IAnyObject;
.  ..

然后在访问属性的时候,不使用this.proproperties.XXX而使用this.data.XXX as [type]来规避问题

wxs definitions[wxs 的定义声明]

创建了 @types/miniprogram-wxs 声明wxs定义npm的包

@wechat-miniprogram-admin 添加到了maintainer list里了 ,如果有必要官方可以直接更新这个包

定义 WXS 文件可以直接声明引用 miniprogram-wxs

/// <reference types="miniprogram-wxs"/>

//  write typescript code as wxs
const today: Date = getDate();
// javascript code as wxs
var today = getDate();

源文件: https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/miniprogram-wxs

wx.navigateBack(Object object)的改进?

很多api其实都存在这个问题,这个也基本上是一个文档的问题.....
我以wx.navigateBack这个API举例说明吧....

文档中说delta是必填项,也就是说,如果我想要单纯做一个返回,我应该wx.navigateBack({delta:1)

但是返回上一页的逻辑是如此的常用,以至于这个api实际上从我所入坑的1.2.几版本,delta其实就是一个可选参数,或者说这个api本来就可以不传入对象,wx.navigateBack()的调用结果一直都是返回上一页,根本不会报错....

所以我相信不止我一个开发者会大量的写wx.navigateBack()这种调用形式.....而在TS里就会报错,我每次都是手动把delta:number这类改成delta?:number

再举一种例子,同理类似的API还有wx.setTabBarStyle,wx.setBackgroundColor,setNavigationBarColor这三货。
这三个API的参数很多都是必填,但是开发中会经常遇到就想改特定的某一项,这个时候只传这一项实际上是完全OK的,根本不需要把其他必填的参数都按照原来的再传一遍......

所以请求可不可以把实际上可以省略的这种通用api的调用也给改一下呢?

[cloud] 重复定义 (与lib.es5)

/**
* Make all properties in T required
*/
type Required<T> = { [P in keyof T]-?: T[P] };
/**
* Exclude from T those types that are assignable to U
*/
type Exclude<T, U> = T extends U ? never : T;
/**
* Extract from T those types that are assignable to U
*/
type Extract<T, U> = T extends U ? T : never;
/**
* Exclude null and undefined from T
*/
type NonNullable<T> = T extends null | undefined ? never : T;
/**
* Obtain the return type of a function type
*/
type ReturnType<T extends (...args: any[]) => any> = T extends (
...args: any[]
) => infer R
? R
: any;
/**
* Obtain the return type of a constructor function type
*/
type InstanceType<T extends new (...args: any[]) => any> = T extends new (
...args: any[]
) => infer R
? R
: any;

这部分声明在TypeScriptlib.es5的定义中已经包含这个了

https://github.com/Microsoft/TypeScript/blob/master/lib/lib.es5.d.ts#L1421-L1489

小程序的定义应该是依赖ES5(或与ES5共存的),
这部分不应该再次引入,否在会造成重复定义的问题

和 Babel 7 一起使用

babel 7 支持 typescript 了,但是不支持 namespace,能否像 Component 那样移除 namespace ?

[Component]behaviors拓展

自定义组件支持拓展behaviors,见自定义组件扩展

拓展以后可能会新增属性,如官方的computed:

const beh = require('./behavior.js')
Component({
  behaviors: [beh],
  data: {
    a: 0,
  },
  computed: {
    b() {
      return this.data.a + 100
    },
  },
  methods: {
    onTap() {
      this.setData({
        a: ++this.data.a,
      })
    }
  }
})

此时会报错。

命名规则和版本?

最近更新的2.7.x 修改了namespace,这是一个完全的break change.
已经和2.6.x以及之前的 完全不兼容了,甚至导致一些项目build break,(从版本上将完全是两个大版本的变化)。

这种namespace以及interface名称是不是应该有个确定规则?(而不是随意更改)

另外对于break change 能否应该提供一下changelog?

openCard和 addCard的cardList类型错误

interface OpenCardOption {
    /** 需要打开的卡券列表 */
    cardList: OpenCardRequestInfo;
    /** 接口调用结束的回调函数(调用成功、失败都会执行) */
    complete?: OpenCardCompleteCallback;
    /** 接口调用失败的回调函数 */
    fail?: OpenCardFailCallback;
    /** 接口调用成功的回调函数 */
    success?: OpenCardSuccessCallback;
  }

应为

interface OpenCardOption {
    /** 需要打开的卡券列表 */
    cardList: OpenCardRequestInfo[];
    /** 接口调用结束的回调函数(调用成功、失败都会执行) */
    complete?: OpenCardCompleteCallback;
    /** 接口调用失败的回调函数 */
    fail?: OpenCardFailCallback;
    /** 接口调用成功的回调函数 */
    success?: OpenCardSuccessCallback;
  }

文档类型描述为
image

部分参数调整建议

1 按照文档中 Animation Step 方法应返回 Animation,以支持链式调用,现在返回了 void
2 SelectorQuery 中 selectAll 方法缺少 selector 参数
3 Storage 相关方法只定义了基础 object 类型,应使用联合类型 object | string | boolean
4 canvasToTempFilePath 和 createCanvasContext 缺少在组件环境下的 component this 参数

参数调整建议

像stopPullDownRefresh(option: StopPullDownRefreshOption): void; 里的option应该改成可空类型,现在调用wx.stopPullDownRefresh({}) 加个空对象参数才不会报错

wx.chooseMessageFile返回结果参数类型错误

interface ChooseMessageFileSuccessCallbackResult {
/** 返回选择的文件的本地临时文件对象数组 */
tempFiles: ChooseFile;
}

应该是返回的ChooseFile数组

interface ChooseMessageFileSuccessCallbackResult {
/** 返回选择的文件的本地临时文件对象数组 */
tempFiles: ChooseFile[];
}

chooseImage在真机上使用异常

官方文档上sizeType和sourceType的定义类型为Array.string,但定义文件里将这两个参数的类型分别定义为了'original' | 'compressed'和 'album' | 'camera',虽然在调试工具上可以正常使用,但是在iphone上无法正常调用chooseImage,将这两个参数定义修改为('original' | 'compressed') []和('album' | 'camera') []就正常了。

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.