码迷,mamicode.com
首页 > 其他好文 > 详细

[TypeScript] Define a function type

时间:2017-07-24 10:02:41      阅读:129      评论:0      收藏:0      [点我收藏+]

标签:const   test   nbsp   can   use   pre   which   define   val   

type DigitValidator = (char) => boolean;

const numericValidator = (char) => /[0-9]{1}/.test(char);

export const digitValidators: {[key: string]: DigitValidator} = {
  9: numericValidator
};

 

We can use ‘type‘ keyword to define a function type. 

‘digitValidators‘, is a mapping object, return a function which type is DigitValidator.

[TypeScript] Define a function type

标签:const   test   nbsp   can   use   pre   which   define   val   

原文地址:http://www.cnblogs.com/Answer1215/p/7226858.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!