Skip to content

navigator.share is not always a function #42809

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
roebuk opened this issue Feb 15, 2021 · 7 comments
Open

navigator.share is not always a function #42809

roebuk opened this issue Feb 15, 2021 · 7 comments
Labels
Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Help Wanted You can do this
Milestone

Comments

@roebuk
Copy link

roebuk commented Feb 15, 2021

Bug Report

navigator.share is undefined is many browsers, yet TypeScript reports it as "the function is always defined"

πŸ”Ž Search Terms

navigator.share
share

πŸ•— Version & Regression Information

Version 4.1.5 & Nightly

⏯ Playground Link

https://www.typescriptlang.org/play?#code/JYMwBAFAdghgbsA5jALgewE4DoDOALGDAUwEowBvAWACgw6wBjNKHNAGyKzbUQgHIAKniJhYKYHBH5CIkEVQBXYmGA4VAWwAOHdUSgoiAEz4kA3DQC+YImxwiqtekxbtO3XoOGjUEqQWVyisqqomgoGtpEuvpGJubUFkA

πŸ’» Code

if (navigator.share) {
    console.log('The native share feature is implemented');
} else {
    console.log('The native share feature is not implemented');
}

πŸ™ Actual behavior

TypeScript reports it as "the function is always defined"

πŸ™‚ Expected behavior

If should report navigator.share as maybe being present.

@MartinJohns
Copy link
Contributor

I'm surprised this definition is provided in the first place, given that it's only specified in a draft specification and only two browsers support it (Edge and Safari, not even Chrome or Firefox).

@IllusionMH
Copy link
Contributor

There is ton of definitions from Edge Web IDLs so I think this definition is one from Edge.

@IllusionMH
Copy link
Contributor

IllusionMH commented Feb 15, 2021

Apparently no - it's not from Edge.

microsoft/TypeScript-DOM-lib-generator#837
#18642

And related to microsoft/TypeScript-DOM-lib-generator#957

@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Help Wanted You can do this labels Feb 18, 2021
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Feb 18, 2021
@pridemusvaire
Copy link

I have a workaround for now., set a state variable that I update when the component loads

const [canShare, setCanShare] = React.useState<any | undefined>(undefined);
useEffect(()=> {setCanShare(navigator.share)}, [])

@rizadh
Copy link

rizadh commented Dec 16, 2021

Ran into the same issue. Discovered that using navigator['share'] instead also works around the Typescript error, at least with my installed version of TypeScript 4.5.3.

@jnastaskin
Copy link

Ran into the same issue. Discovered that using navigator['share'] instead also works around the Typescript error, at least with my installed version of TypeScript 4.5.3.

This worked for me thank you!!

@gettersgetmore
Copy link

or 'share' in navigator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Help Wanted You can do this
Projects
None yet
Development

No branches or pull requests

8 participants