【发布时间】:2018-10-31 00:24:09
【问题描述】:
我想将 RedisGetHashJob 强制转换为 RedisKey 类型,但出现错误...
我的类型:
export type RedisKey = {
source: string,
destination: string,
type: string,
id: string,
groupId: string,
pid?: string,
};
export type RedisGetHashJob = {
source: string,
destination: string,
type: string,
id: string,
groupId: string,
pid: string,
};
我有两个功能:
1 - 函数 createKey(obj: RedisKey): 字符串
2 - 函数 getHashJob(obj: RedisGetHashJob): 承诺
在我的第二个函数中,必须设置 pid 属性。但是当我尝试这样称呼它时:
function getHashJob(obj: RedisGetHashJob): Promise<string> {
const key = createKey(obj);
....
}
我有以下错误:
Error: src/common/lib/redis.js:60
60: const key = createKey(obj);
^^^ object type. This type is incompatible with the expected param type of
15: export function createKey(obj: RedisKey): string {
^^^^^^^^ object type
Property `pid` is incompatible:
8: pid?: string,
^^^^^^ undefined. This type is incompatible with. See: src/types/redis.js:8
26: pid: string,
^^^^^^ string. See: src/types/redis.js:26
你知道完成这项工作的好方法吗?
问候,
【问题讨论】:
标签: ecmascript-6 flowtype