给出以下代码:
document.getElementById('exampleButton').innerHTML = '<img src="' + theme_directory + '/svg/icons/cursor.svg" width="32" height="32" title="">Example';
是否有任何方法可以从const disconnected = () =>
({
type: 'DISCONNECTED'
} as const);
const connected = () =>
({
type: 'CONNECTED'
} as const);
type Events = ReturnType<typeof disconnected | typeof connected>;
中提取类型,该类型等于联合的每个成员的Events
属性中的一组值。我希望得到类似type
答案 0 :(得分:3)
一种非常简单的方法是:
type Events = ReturnType<typeof disconnected | typeof connected>['type']; //'DISCONNECTED' | 'CONNECTED'