Property 'share' does not exist on type 'Navigator'

For anyone looking for a proper answer, just add this to your global.d.ts file:

type ShareData = {
    title? : string;
    text? : string;
    url? : string;
};

interface Navigator
{
    share? : (data? : ShareData) => Promise<void>;
}

This properly reflects the level 1 API.


Based on this answer, you can try to define a variable of type any and assign to it your value of Type Navigator. The isssue is related to typeScript typings.

let newVariable: any;

newVariable = window.navigator;

if (newVariable && newVariable.share) {
  newVariable.share({
    title: 'title',
    text: 'description',
    url: 'https://soch.in//',
  })
    .then(() => console.log('Successful share'))
    .catch((error) => console.log('Error sharing', error));
} else {
  alert('share not supported');
}

Another option would be to extend the interface Navigator as it is suggested in the link I posted above.