-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptThe issue relates to the different libraries shipped with TypeScriptExperience EnhancementNoncontroversial enhancementsNoncontroversial enhancements
Milestone
Description
TypeScript Version: Version 3.5.1
Code
touchDevice = (('ontouchstart' in window) || (window.navigator.msMaxTouchPoints > 0));Expected behavior:
No error
Actual behavior:
Produces the error: Property 'navigator' does not exist on type 'never'.
More
Apparently this issue happens due to something called "type narrowing", the idea being that TypeScript is warning us that the code after the || is unreachable. But that's simply not true. Modern browsers without touch support may have an undefined window.ontouchstart. So it appears that TypeScript is treating ontouchstart as a required property, when in fact it should be optional.
htinc
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptThe issue relates to the different libraries shipped with TypeScriptExperience EnhancementNoncontroversial enhancementsNoncontroversial enhancements



