-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Closed
Description
π Search Terms
TypeScript Record Function TypeError
π Version & Regression Information
5.3.3
β― Playground Link
π» Code
var funcmap: Record<string, () => void> = {};
var func = 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
Metadata
Metadata
Assignees
Labels
No labels