如何使用具有相同键但值类型不同的输入和输出对象来键入函数? [英] How do I type a function with input and output objects with the same keys but different value types?

查看:48
本文介绍了如何使用具有相同键但值类型不同的输入和输出对象来键入函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我有一个函数可以将一个对象转换为另一个对象,就像一个字典,但是我不知道如何键入它.

Basically, I have a function that will transform an object into a different object, and it's like a dictionary, but I don't know how to type it.

var myFunctions = {
  a: () => something1,
  b: () => something2,
  [...]
}

被转化为

var myObject = {
  a: something1,
  b: something2
  [...]
}

推荐答案

使用Flow 0.33+,您可以使用$ObjMap

With Flow 0.33+ you can use $ObjMap

type ExtractCodomain = <V>(v: () => V) => V;
declare function f<O>(o: O): $ObjMap<O, ExtractCodomain>;

这篇关于如何使用具有相同键但值类型不同的输入和输出对象来键入函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆