Reputation: 74
I'm having a simple Record
with string keys that defined like this:
type Data = Record<string, string>;
I'm accessing values in a really simple way:
const data: Data = {};
const entry = data['entry'];
Is there a way to tell Typescript to treat these values as string | undefined
and not simply string
, except defining maps with Record<string, string | undefined>
?
Strict mode is enabled, so I didn't expect to see the behavior in the real code.
Upvotes: 0
Views: 711
Reputation: 184416
For that you need to set the flag noUncheckedIndexedAccess
, which is not part of strict
because it was deemed to be potentially too disruptive.
Upvotes: 1