浏览代码

extract FlagHandler type

mightyplow 5 年之前
父节点
当前提交
86153093bd
共有 1 个文件被更改,包括 2 次插入1 次删除
  1. 2 1
      src/flags.ts

+ 2 - 1
src/flags.ts

@@ -5,7 +5,8 @@ const $toggle = (flag: number, sequence = 0) => sequence ^ flag
 
 const combine = (flags: number[]) => flags.reduce((flags, flag) => flags + flag, 0)
 
-const createMultiFlagHandler = <T>(fn: (flag: number, flags: number) => T) => 
+type FlagHandler<T> = (flag: number, flags: number) => T
+const createMultiFlagHandler = <T extends number | boolean>(fn: FlagHandler<T>) => 
     (flag: number | number[], sequence = 0): T => 
         fn(Array.isArray(flag) ? combine(flag) : flag, sequence)