类型定义中具有通配符的动态键



我对 Typescript 很陌生,找不到是否可以在类型定义中使用动态键。

例如,这是我正在努力的类型:

export interface IQuery {
locale?: string;
include?: number;
limit?: number;
select?: string;
skip?: number;
order?: string;
// all keys starting with "fields." (e.g. "fields.name[ne]") should be a string
'fields.*'?: string;
}

提前感谢!

使用模板文本类型:

export interface IQuery {
// ...
[key: `fields.${string}`]: string;
}

最新更新