简体   繁体   English

flowtype:将函数的返回类型更改为void

[英]flowtype: change function return type to void

I need to change the return type of a function to void. 我需要将函数的返回类型更改为void。

For example: 例如:

import { func_one } from './examples';

// FuncOneType is a function type with the same signature
// as func_one.
type FuncOneType = typeof func_one;

// FuncOneTypeWithoutReturn is similar to FuncOneType but 
// the return type is void. This works.
const func_one_void = (...args) => {func_one(...args)};
type FuncOneTypeVoidReturn = typeof func_one_void;

// I need something like to avoid the intermediate
// function func_one_void. How can I achieve this?
type FuncOneTypeVoidReturn = $Arguments<func_one> => void;

We chatted about this a bit on a GitHub Issue, but wanted to put the answer here just in case someone lands on this question via Google. 我们在GitHub Issue上聊了一下,但是想把答案放在这里,以防万一有人通过Google找到了这个问题。 Flow currently has no way to represent "the type of all the arguments to a function" or to type a higher-order function that takes another function and preserves its argument types but returns a different type. Flow当前无法表示“一个函数的所有参数的类型”或键入一个采用另一个函数并保留其参数类型但返回不同类型的高阶函数。

(Also note that the func_one_void example above doesn't really work as you would like. The arguments to that function no longer have any types but are instead just any .) (还要注意,上面的func_one_void示例实际上并没有像您想要的那样工作。该函数的参数不再具有任何类型,而只是any类型。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM