I have the following interface:
interface ClassSchedule {
[key: string]: string;
}
However, I am receiving an error that my key is possibly undefined. How do I account for this?
interface ClassSchedule {
[key: string]: string;
}
It sounds like you have the --noUncheckedIndexedAccess compiler option enabled.
You can avoid this error by:
if statement).! after the key (e.g. foo.bar! or `foo["bar"]!) to assert that the value will always be non-null.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With