【发布时间】:2017-09-11 03:41:12
【问题描述】:
假设我有以下内容:
export const ContentType = {
Json: "application/json",
Urlencoded: "application/x-www-form-urlencoded",
Multipart: "multipart/form-data",
};
export interface RequestOptions {
contentType: string,
}
const defaultOptions: Partial<RequestOptions> = {
contentType: ContentType.Json,
};
我将如何限制 contentType 以便只使用在 ContentType 中声明的键?
【问题讨论】:
-
您不想将
contentType限制为ContentType的值,而不是键吗? -
看起来你可以使用像this answer这样的查找类型...
标签: typescript