代码之家  ›  专栏  ›  技术社区  ›  james emanon

流类型和类上的映射

  •  0
  • james emanon  · 技术社区  · 9 年前

    我有几个类被激发,它们的“fireScript”方法,在一个promise方法中。全部的我不知道当一个类在地图上移动时,我会如何注释它。

    import ShoeClass from 'products/ShoeClass';
    import HatClass from 'products/HatClass';
    
    //somewhere else the code
    
    await promise.all([ShoeClass, HatClass]
      .map(product => product.firScript()))
    

    这给了我错误,所以我试图为一个类找到一个泛型流类型,这可能吗?

      .map(product <---- this wants an annotation. Each mapped class is different obviously, but how would I annotate it? With a generic?
    
    1 回复  |  直到 9 年前
        1
  •  1
  •   Tr1et    9 年前

    您可以尝试:

    await promise.all(
      [ShoeClass, HatClass].map((product: Class<*>):Promises<*> => product.firScript()));
    

    here 供快速参考。