const arr = [
{ key: 'one', value: '1' },
{ key: 'two', value: '2' },
{ key: 'three', value: '3' },
] as const;
type Keys = GetKeys<typeof arr>;
如何定义GetKeys
使得Keys
为'one' | 'two' | 'three'
?
答案 0 :(得分:1)
您只想几次使用lookup type(也称为“索引访问类型”)从数组中获取数字键元素,然后从这些键的public async Task Play(CancellationToken cancel)
{
if (State == PlaybackState.Playing)
return;
if (RemainingAirTime == null)
RemainingAirTime = ETimeSpan.FromSeconds(Display.Settings.ScrollTime);
if (cancel.IsCancellationRequested)
return;
_ct = new Countdown(RemainingAirTime.BaseSpan);
_ct.Elapsed += _ct_Elapsed;
_ct.Start();
try {
Draw();
}catch(System.Exception ex) {
Blenet.Exceptions.ExceptionHandler.HandleException(ex, "Error while drawing", this);
}
State = PlaybackState.Playing;
await Task.Delay(RemainingAirTime.BaseSpan, cancel);
if(State == PlaybackState.Playing)
await Reset();
}
private void _ct_Elapsed(TimeSpan obj)
{
if (State == PlaybackState.Playing)
RemainingAirTime = new ETimeSpan(obj);
}
键属性中获取:
"key"
希望有所帮助;祝你好运!