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

Incompatible type for ES6 Proxy set handler using ES6 shorthand syntax #11445

Closed
httpdigest opened this issue Oct 7, 2016 · 3 comments
Closed
Labels
Duplicate An existing issue was already created

Comments

@httpdigest
Copy link

httpdigest commented Oct 7, 2016

I recently tried to use the ES6 Proxy class to create immutable objects from given 'target' objects, using the following code:

function makeImmutable(target) {
  return new Proxy(target, {
    set(target, property, value, receiver) {
      throw '...';
    }
  });
}

Compiling this with:
tsc --lib es6 test.ts

fails with the following error message:

test.ts(2,28): error TS2345: Argument of type '{ set(target: any, property: PropertyKey, value: any, receiver: any): void; }' is not assignable to parameter of type 'ProxyHandler<any>'.
  Types of property 'set' are incompatible.
    Type '(target: any, property: PropertyKey, value: any, receiver: any) => void' is not assignable to type '(target: any, p: PropertyKey, value: any, receiver: any) => boolean'.
      Type 'void' is not assignable to type 'boolean'.

However, when not using the ES6 "function property" shorthand syntax, and instead doing the following:

function makeImmutable(target) {
  return new Proxy(target, {
    set: function(target, property, value, receiver) {
      throw '...';
    }
  });
}

Everything compiles fine.

Typescript version: 2.1.0-dev.20161007

@RyanCavanaugh RyanCavanaugh added Needs Investigation This issue needs a team member to investigate its status. and removed Needs Investigation This issue needs a team member to investigate its status. labels May 24, 2017
@ThorstenBux
Copy link

Got the same

@mhegazy
Copy link
Contributor

mhegazy commented Nov 20, 2017

This is a duplicate of #16608, you can find more information about why never is not automatically inferred in this case in #8767.

Adding an explicit type annotation, be it never, should address the issue.

@mhegazy mhegazy added Duplicate An existing issue was already created and removed Needs Investigation This issue needs a team member to investigate its status. labels Nov 20, 2017
@typescript-bot
Copy link
Collaborator

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

5 participants