type MaybeThereIsAValue = { [p: string]: string | undefined } ... let bar: MaybeThereIsAValue = {}; const key = "carpe"; bar[key] = "diem"; const why = bar[key]; // why is string | undefined
Why is why
string | undefined
since I am literally assigning a value to bar[key]
in the previous line ?
How can I avoid it ?
Check example here
https://stackoverflow.com/questions/66930004/why-typescript-complains-objects-key-is-undefined-even-if-the-previous-command April 03, 2021 at 06:20PM
没有评论:
发表评论