简体   繁体   English

OpenSeadragon 在类型定义中缺少道具

[英]OpenSeadragon missing prop in types definition

I have an application written in React Typescript and use OpenSeadragon ( https://openseadragon.github.io/ ) to display images.我有一个用 React Typescript 编写的应用程序,并使用 OpenSeadragon ( https://openseadragon.github.io/ ) 来显示图像。 To get type definitions for OpenSeadragon I use @types/openseadragon: https://www.npmjs.com/package/@types/openseadragon要获取 OpenSeadragon 的类型定义,我使用 @types/openseadragon: https://www.npmjs.com/package/@types/openseadragon

I want to use the toolbar prop coming from OpenSeadragon ( https://openseadragon.github.io/examples/ui-toolbar/ ), however, this prop is missing in the types definition.我想使用来自 OpenSeadragon 的工具栏道具( https://openseadragon.github.io/examples/ui-toolbar/ ),但是,类型定义中缺少此道具。 So, when I try to use the prop in the code as so:所以,当我尝试在代码中使用道具时:

OpenSeadragon({
                id: 'openseadragon-container',
                toolbar: 'toolbarDiv',
            });

I get the following error:我收到以下错误:

(property) toolbar: string Argument of type '{ id: string; (属性)工具栏:字符串类型的参数'{ id:字符串; toolbar: string;工具栏:字符串; }' is not assignable to parameter of type 'Options'. }' 不可分配给“选项”类型的参数。 Object literal may only specify known properties, and 'toolbar' does not exist in type 'Options'. Object 文字只能指定已知属性,并且“选项”类型中不存在“工具栏”。

I am wondering if there are any way to overcome this and how I can be able to use the toolbar prop?我想知道是否有任何方法可以克服这个问题以及如何使用工具栏道具? Any suggestions?有什么建议么?

One way to solve this would be to create an interface of the Options type and include the toolbar in there.解决此问题的一种方法是创建Options类型的interface并在其中包含toolbar So you would extend the existing Options type and include all the parameters you need.因此,您将扩展现有的Options类型并包含您需要的所有参数。

interface OptionsWithToolbar extends OpenSeadragon.Options {
  toolbar: string;
}

OpenSeadragon({
  id: "openseadragon-container",
  toolbar: "toolbarDiv"
} as OptionsWithToolbar);

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

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