How to fix error TS2339: Property 'userLanguage' does not exist on type 'Navigator'.

Problem:

When developing with typescript,  e.g. with Angular2, you get an error message similar to this one:

ts2339_error.txt
error TS2339: Property 'userLanguage' does not exist on type 'Navigator'.

Solution

Check the error message for the correct file and line. Look for a statement like

navigator_userlanguage_access.js
window.navigator.userLanguage

Currently typescript does not have userLanguage as a property (tested with typescript up to 2.7.1), although it should already be fixed according to this issue.

You can work around this by simply replacing the statement listed above by

navigator_userlanguage_workaround.js
window.navigator['userLanguage']

Using this approach, Typescript will simply not check if the attribute is present or not.


Check out similar posts by category: Typescript