flow generic type for function [removed]arrow functions)

前端 未结 3 611
旧巷少年郎
旧巷少年郎 2021-02-07 21:48

I usually try to keep flow function types separate from their implementation. It\'s a slightly more readable when I write:

type Fn = string => string;
const a         


        
3条回答
  •  遥遥无期
    2021-02-07 21:54

    So I have noticed that if I use bounded generics, it'll work:

    type H = (input: T) => T;
    const h:H<*> = i => i;
    
    const a: string = h('apple');      // √
    const b: number = h(7);            // √
    const c: {} = h({ nane: 'jon' });  // √
    

    Don't ask me WHY.

提交回复
热议问题