Property 'share' does not exist on type 'Navigator'
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.
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.
This also works and we don't need to create a newVariable.
if (window.navigator && window.navigator.share) { window.navigator['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');}