Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Typescript初始化数据加载器时出现类型错误_Typescript_Graphql_Dataloader - Fatal编程技术网

使用Typescript初始化数据加载器时出现类型错误

使用Typescript初始化数据加载器时出现类型错误,typescript,graphql,dataloader,Typescript,Graphql,Dataloader,我正在尝试使用以下代码初始化DataLoader的实例: const authorLoader = new DataLoader(async (keys:string[]) => { // Return an author for each book }); 我得到以下错误: Argument of type '(keys: string[]) => Promise<Author[]>' is not assignable to parameter of typ

我正在尝试使用以下代码初始化DataLoader的实例:

const authorLoader = new DataLoader(async (keys:string[]) => {
    // Return an author for each book
});
我得到以下错误:

Argument of type '(keys: string[]) => Promise<Author[]>' is not assignable to parameter of type 'BatchLoadFn<string, Author>'.
Types of parameters 'keys' and 'keys' are incompatible.
The type 'readonly string[]' is 'readonly' and cannot be assigned to the mutable type 'string[]'
类型的参数”(key:string[])=>Promise”不可分配给“BatchLoadFn”类型的参数。
参数“键”和“键”的类型不兼容。
类型“readonly string[]”为“readonly”,无法分配给可变类型“string[]”
为什么会出现此错误?如何修复?我阅读了
泛型和dataloader的源代码,但还没有找到解决方案


注意:
keys
的类型是
string[]
而不是
number[]
,因为我使用的是
uuid

正如错误消息所说,数据加载器希望函数参数是
只读字符串[]
,但您已经将其注释为
string[]

const authorLoader = new DataLoader(async (keys: readonly string[]) => {
    // Return an author for each book
});

哇,我很难为情地看到解决方案这么简单!谢谢,我们都去过!