1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > typescript之typings(*.d.ts类型声明)

typescript之typings(*.d.ts类型声明)

时间:2021-01-03 05:04:08

相关推荐

typescript之typings(*.d.ts类型声明)

参考微信小程序官方ts基础工程:

tsconfig.json

类型引入之后,就可以在我们的ts代码中,直接调用wx 相关方法,编译期不会报错,运行期必须在微信环境下!

// wx 通过 *.d.ts 类型声明, 相当于定义了“全局对象”,类似 window 对象/*** 拨号* @param phoneNumber*/export const makePhoneCall = function (phoneNumber: string) {wx.makePhoneCall({phoneNumber,});};

引入node_modules中的类型声明:

修改typings/index.d.ts

/// <reference types="miniprogram-api-typings" />// wx 通过 *.d.ts 类型声明, 相当于定义了“全局对象”,类似 window 对象/*** 拨号* @param phoneNumber*/export const makePhoneCall = function (phoneNumber: string) {wx.makePhoneCall({phoneNumber,});};

需要安装miniprogram-api-typings依赖包:npm i miniprogram-api-typings -D

参考:

/docs/handbook/declaration-files/consumption.html

/docs/handbook/tsconfig-json.html

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。