【问题标题】:How do you use interfaces with two extend parameters used?您如何使用带有两个扩展参数的接口?
【发布时间】:2020-08-06 02:04:38
【问题描述】:

我在 react-table 中使用 typescript 时试图理解代码,但遇到了这些类型的接口

 export interface TableInstance<D extends object = {}>
    extends Omit<TableOptions<D>, 'columns' | 'pageCount'>,
        UseTableInstanceProps<D> {}

注意界面中的两个extends关键字。调用时生成一个表实例

    export function useTable<D extends object = {}>(
    options: TableOptions<D>,
    ...plugins: Array<PluginHook<D>>
): TableInstance<D>;

之后我可以访问从UseTableInstanceProps继承的TableInstance属性

我是不是说TableInstance 是一个继承OmitUseTableInstanceProps 属性的对象?

这个省略是什么意思?有什么资源可以帮助我理解这种语法吗?

/**
 * Construct a type with the properties of T except for those in type K.
 */
type Omit<T, K extends keyof any> = Pick<T, Exclude<keyof T, K>>;

【问题讨论】:

  • 我的回答有帮助吗?

标签: typescript typescript-typings typescript-generics


【解决方案1】:

Omit、Pick 和 Exclude 是 TypeScript 实用程序类型,如 here 所述。

因此 react-table 正在创建自己的 Omit 版本,即它与 Omit TypeScript 实用程序类型不同。至于“keyof”关键字参考this

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-23
    • 1970-01-01
    • 2018-08-22
    • 1970-01-01
    相关资源
    最近更新 更多