Promises with typescript-2.x gives error :Cannot invoke an expression whose type lacks a call signature

Akhilesh Kumar

After upgrading angular to 4.x from 2.x and typescript to 2.x started giving following error which was working fine with previous version

Cannot invoke an expression whose type lacks a call signature. Type '((onfulfilled?: (value: MediaStream) => TResult1 | Prom...' has no compatible call signatures.

My code is as following

getMediaStream(options:{video: boolean, audio: boolean}) {
    let self: Caller = this;
    return self.getUserMedia(options)
      .then(stream => {
        console.log('got our media stream:', stream);
        self.privateMedia = createObjectURL(stream);
        self.privateStream = stream;
        return stream;
      })
      .catch(() => {
        console.log('Could not get access to microphone & camera');
      });
  }

  public getUserMedia(constraints) {
    if (window.navigator.mediaDevices && window.navigator.mediaDevices.getUserMedia) {
      return window.navigator.mediaDevices.getUserMedia(constraints);
    }

    return new Promise((resolve, reject) => {
      const getMedia = window.navigator.getUserMedia;
      if (!getMedia) reject(new Error('Browser unsupported'));
      getMedia.call(navigator, constraints, resolve, reject);
    });
  }
Akhilesh Kumar

Typecasting self.getUserMedia(options) to any/Promise resolved the problem.

So I used following code and it worked:

getMediaStream(options:{video: boolean, audio: boolean}) {
    let self = this;
    return (<Promise>self.getUserMedia(options))// in place of promise 'any' or other any superclass to promise will work as well 
      .then(stream => {
        console.log('got our media stream:', stream);
        self.privateMedia = createObjectURL(stream);
        self.privateStream = stream;
        return stream;
      }).catch(() => {
        console.log('Could not get access to microphone & camera');
      });
  }

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Error: Cannot invoke an expression whose type lacks a call signature

From Java

Cannot invoke an expression whose type lacks a call signature

From Java

object[] | object[] type lacks a call signature for 'find(),foreach()'

From Dev

Invoke method with arguments gives error

From Dev

Exporting typescript function "lacks a call signature"

From Dev

SKNode subclass generates error: cannot invoke initializer for type "X" with no arguments

From Dev

TypeScript Compile Error Cannot invoke an expression whose type lacks a call signature

From Dev

TypeScript: Cannot use 'new' with an expression whose type lacks a call or construct signature

From Dev

How to fix "TS2349: Cannot invoke an expression whose type lacks a call signature"

From Dev

Type declaration file and call signature error

From Dev

error TS2349: Cannot invoke an expression whose type lacks a call signature

From Dev

Error "Type IFoo<T> requires a construct signature but type Foo<T> lacks one" when implementing a newable generic interface in TypeScript

From Dev

Type signature for a TypeScript HOF

From Dev

why gives error Expression cannot contain lambda expressions?

From Dev

Cannot invoke + with an argument of type CGRect error in Swift

From Dev

Exporting typescript function "lacks a call signature"

From Dev

TypeScript 1.6 error: JSX element type XXX does not have any construct or call signature

From Dev

typescript Cannot invoke an expression whose type lacks a call signature?

From Dev

Type declaration file and call signature error

From Dev

Typescript Compiler Cannot invoke an expression whose type lacks a call signature

From Dev

TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. Mongoose

From Dev

Cannot invoke value of type

From Dev

Cannot invoke an expression whose type lacks a call signature. Type has no compatible call signatures

From Dev

Cannot invoke an expression whose type lacks a call signature, while it has a signature

From Dev

TypeScript: Intersection Types for construct signature and a type doesn't work, but for call signature and a type does

From Dev

Typescript cannot invoke expression whost type lacks a call signature

From Dev

How do I fix "Cannot use 'new' with an expression whose type lacks a call or construct signature" in angular 4?

From Dev

Cannot invoke an expression whose type lacks a call signature TypeScript error

From Dev

Cannot invoke an expression whose type lacks a call signature, map

Related Related

  1. 1

    Error: Cannot invoke an expression whose type lacks a call signature

  2. 2

    Cannot invoke an expression whose type lacks a call signature

  3. 3

    object[] | object[] type lacks a call signature for 'find(),foreach()'

  4. 4

    Invoke method with arguments gives error

  5. 5

    Exporting typescript function "lacks a call signature"

  6. 6

    SKNode subclass generates error: cannot invoke initializer for type "X" with no arguments

  7. 7

    TypeScript Compile Error Cannot invoke an expression whose type lacks a call signature

  8. 8

    TypeScript: Cannot use 'new' with an expression whose type lacks a call or construct signature

  9. 9

    How to fix "TS2349: Cannot invoke an expression whose type lacks a call signature"

  10. 10

    Type declaration file and call signature error

  11. 11

    error TS2349: Cannot invoke an expression whose type lacks a call signature

  12. 12

    Error "Type IFoo<T> requires a construct signature but type Foo<T> lacks one" when implementing a newable generic interface in TypeScript

  13. 13

    Type signature for a TypeScript HOF

  14. 14

    why gives error Expression cannot contain lambda expressions?

  15. 15

    Cannot invoke + with an argument of type CGRect error in Swift

  16. 16

    Exporting typescript function "lacks a call signature"

  17. 17

    TypeScript 1.6 error: JSX element type XXX does not have any construct or call signature

  18. 18

    typescript Cannot invoke an expression whose type lacks a call signature?

  19. 19

    Type declaration file and call signature error

  20. 20

    Typescript Compiler Cannot invoke an expression whose type lacks a call signature

  21. 21

    TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. Mongoose

  22. 22

    Cannot invoke value of type

  23. 23

    Cannot invoke an expression whose type lacks a call signature. Type has no compatible call signatures

  24. 24

    Cannot invoke an expression whose type lacks a call signature, while it has a signature

  25. 25

    TypeScript: Intersection Types for construct signature and a type doesn't work, but for call signature and a type does

  26. 26

    Typescript cannot invoke expression whost type lacks a call signature

  27. 27

    How do I fix "Cannot use 'new' with an expression whose type lacks a call or construct signature" in angular 4?

  28. 28

    Cannot invoke an expression whose type lacks a call signature TypeScript error

  29. 29

    Cannot invoke an expression whose type lacks a call signature, map

HotTag

Archive