[TypeScript] Define a function type

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.

posted @ 2017-07-24 02:41  Zhentiw  阅读(469)  评论(0)    收藏  举报