Skip to content
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

[lib.d.ts BUG] navigator.mediaDevices.getUserMedia returns PromiseLike (actually returns a Promise) #10242

Closed
jhm-ciberman opened this issue Aug 10, 2016 · 12 comments
Labels
Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Duplicate An existing issue was already created

Comments

@jhm-ciberman
Copy link

TypeScript Version: atom-typescript

Code

var a = navigator.mediaDevices.getUserMedia(options);
a.catch( () => console.log ); 
//ERROR: 'catch' does not exists on type 'PromiseLike<MediaStream>'

Expected behavior:
Acording to MDN, navigator.mediaDevices.getUserMedia returns a Promise (with a catch method), not a PromiseLike (without catch method).

Actual behavior:
navigator.mediaDevices.getUserMedia returns a PromiseLike<MediaStream>
It needs to return a Promise<MediaStream>

@hongbo-miao
Copy link

hongbo-miao commented Aug 13, 2016

I am using TypeScript 2, and got same error, originally asked on Stack Overflow

maiermic's answer:

The build-in library dom declares the issue causing definition (see lib.dom.d.ts):

getUserMedia(constraints: MediaStreamConstraints): PromiseLike<MediaStream>;

whereas @types/webrtc declares your expected definition (see MediaStream.d.ts):

getUserMedia(constraints: MediaStreamConstraints): Promise<MediaStream>;

@mhegazy
Copy link
Contributor

mhegazy commented Aug 27, 2016

To fix this we will need to put Promise in lib.d.ts; but looks needed.

@mhegazy mhegazy added the Bug A bug in TypeScript label Aug 27, 2016
@mhegazy mhegazy added this to the TypeScript 2.1 milestone Aug 27, 2016
@mhegazy mhegazy added the Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript label Aug 27, 2016
@zhengbli
Copy link
Contributor

zhengbli commented Sep 8, 2016

So we should get an ES6 version of the dom.generated.d.ts that replaces all PromiseLike with Promise, when the user is either targeting es6+ or somehow speficied in the --lib compiler options.

@mhegazy
Copy link
Contributor

mhegazy commented Sep 8, 2016

We still need promislike. Let's talk about this. Maybe we should just make es6 the default.

@mhegazy mhegazy modified the milestones: TypeScript 2.1, Community Sep 21, 2016
@prencher
Copy link

Has there been any movement on this? This is a long standing issue at this point.

@aluanhaddad
Copy link
Contributor

ES2015 as the default might make sense, there are already a lot of features in lib.d.ts that are not supported by a number of browsers in wide use. But there is also a lot of stuff in there that would be confusing for ES5.1 users and since TypeScript does not include an official polyfill, which I might add is a very good thing, I'm not sure if this is the right way to go.

@Nek-
Copy link

Nek- commented Dec 12, 2016

So the quick fix is the following:

# TS 2.x only
npm install --save @types/webrtc

(just sayin for newcomers on the issue)

@prencher
Copy link

prencher commented Dec 12, 2016

@Nek- No, that does not fix the issue. Inside of VS Code it correctly resolves the types from @types/webrtc, but in an actual build, TypeScript uses the one from lib.d.ts.

We use that types package and we had to explicitly add as Promise<foo> casts anywhere we use these APIs to make TypeScript not error.

@alcfeoh
Copy link

alcfeoh commented Dec 20, 2016

Any known workaround for this issue? For now I just don't catch exceptions and let them land in the browser console, which gets the job done but still doesn't seem right as I should really be able to catch it from my Promise.

@kjackson87
Copy link
Member

I'm having this issue as well. @prencher could you provide a bit more context for your as Promise fix?

@mhegazy
Copy link
Contributor

mhegazy commented Feb 11, 2017

Duplicate of #13947

@mhegazy mhegazy added the Duplicate An existing issue was already created label Feb 11, 2017
@mhegazy
Copy link
Contributor

mhegazy commented Feb 11, 2017

I should clarify, the generator converts Promise to PromiseLike, which is incorrect.

@mhegazy mhegazy closed this as completed Apr 21, 2017
@mhegazy mhegazy removed this from the Community milestone Apr 26, 2018
@microsoft microsoft locked and limited conversation to collaborators Jul 31, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

9 participants