当前位置: 移动技术网 > IT编程>开发语言>JavaScript > Fundebug前端异常监控插件更新至2.0.0,全面支持TypeScript

Fundebug前端异常监控插件更新至2.0.0,全面支持TypeScript

2019年09月05日  | 移动技术网IT编程  | 我要评论

摘要: 是时候支持ts了!

fundebug前端异常监控服务

fundebug提供专业的前端异常监控服务,我们的插件可以提供全方位的异常监控,可以帮助开发者第一时间定位各种前端异常,包括但不限于javascript执行错误以及http请求错误。

并且,fundebug支持source map还原,记录用户行为以及“录制”用户操作视频,帮助开发者快速复现bug,提高debug效率,欢迎大家免费试用~

fundebug前端异常监控插件更新至2.0.0,全面支持typescript,为使用typescript的用户提供更好的编程体验。

关于typescript

想必大家都听说过typescript:

  • vue 3.0使用typescript重写
  • node.js作者使用typescript开发deno,一个新的javascript后端语言

为什么很多人开始使用ts了呢?

因为javascript没有类型,而typescript有类型的,这样可以提高代码的正确性。另一方面,全面的类型推断意味着编辑器可以提供完备的代码补全和类型错误提醒,提高开发者的开发效率。

对typescript感兴趣的同学,不妨看看ts作者anders hejlsberg的视频introducing typescriptanders hejlsberg是程序员界的传奇人物,c#与typescript都是由他设计主导,年近60依然还在编程,但是,他的视频非常浅显易懂!

全面支持typescript

typescript已经在业界应用了多年,且越来越流行,因此fundebug的前端异常监控插件也应该全面支持typescript了:

  • 所有的代码由javascript切换为typescript
  • 严格遵守tslint的语法规则
  • 为fundebug的各个api编写严格的类型声明文件

对于typescript用户来说,在使用fundebug的api,比如时,可以方便地看到类型提示:

可知,fundebug.test()有2个可选参数name与message,类型都是字符串。

新增fundebug.init()方法

为了兼容严格的typescript语法,我们新增了方法来,例如:

fundebug.init({
    apikey: "api-key"
});

typescript用户在使用全局变量fundebug来配置各种属性时,则会看到报错:

这时,使用// @ts-ignore忽略下一行的报错即可:

// @ts-ignore
fundebug.apikey = 'api-key'

不过,还是推荐大家使用fundebug.init方法进行配置。

fundebug.d.ts

fundebug.d.ts为fundebug前端异常监控插件的类型声明文件:

// type definitions for fundebug-javascript
// project: https://www.npmjs.com/package/fundebug-javascript
// definitions by: fundebug <https://www.fundebug.com>

export as namespace fundebug;

export function init(config: iconfigs): undefined;

export function test(name?: string, message?: string): undefined;

export function notify(
    name: string,
    message: string,
    options?: ioptions
): undefined;

export function notifyerror(error: error, options?: ioptions): undefined;

interface iconfigs {
    apikey: string;
    appversion?: string;
    releasestage?: string;
    user?: iuser;
    metadata?: object;
    callback?: icallback;
    sethttpbody?: boolean;
    httptimeout?: number;
    filters?: object[];
    silent?: boolean;
    silentdev?: boolean;
    silentresource?: boolean;
    silenthttp?: boolean;
    silentwebsocket?: boolean;
    silentconsole?: boolean;
    silentperformance?: boolean;
    samplerate?: number;
    domain?: string;
}

interface iuser {
    name: string;
    email: string;
}

type icallback = (event: object) => void;

interface ioptions {
    metadata?: object;
}

参考

关于fundebug

fundebug专注于javascript、微信小程序、微信小游戏、支付宝小程序、react native、node.js和java线上应用实时bug监控。 自从2016年双十一正式上线,fundebug累计处理了20亿+错误事件,付费客户有阳光保险、核桃编程、荔枝fm、掌门1对1、微脉、青团社等众多品牌企业。欢迎大家!

版权声明

转载时请注明作者 fundebug以及本文地址:

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网