You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
varfuncmap: Record<string,()=>void>={};varfunc=funcmap['does not exist'];func();// TypeError!
π Actual behavior
TypeScript compiles successfully (even with --strict option).
TypeScript infers the type of func variable to be () => void, even though it can be undefined when the key doesn't exist.
π Expected behavior
TypeScript doesn't compile successfully, because the code didn't check whether func is undefined or not.
Additional information about the issue
No response
The text was updated successfully, but these errors were encountered:
Duplicates #13778 (see that and various linked issues there).
You're apparently looking for --noUncheckedIndexedAccess and for many people this turns out to be more annoying than helpful. Often the recommendation is to use (()=>void) | undefined instead of enabling this.
π Search Terms
TypeScript Record Function TypeError
π Version & Regression Information
5.3.3
β― Playground Link
https://www.typescriptlang.org/play?#code/G4QwTgBAZgrgdgYwLYgA4C4ICUCmCD2YAJgDwDOALmAJZwDmANBABQCUEAvAHwTD7VEeHCAG8AvgG4AsAChQkWIk7R4yNAG0A5EXw4yEOPgoQcAD2qVNAXWkzFCNhIgB6ZxAAqAT1Q4AomDBCAEJZIA
π» Code
π Actual behavior
TypeScript compiles successfully (even with
--strict
option).TypeScript infers the type of
func
variable to be() => void
, even though it can beundefined
when the key doesn't exist.π Expected behavior
TypeScript doesn't compile successfully, because the code didn't check whether
func
isundefined
or not.Additional information about the issue
No response
The text was updated successfully, but these errors were encountered: