Closed
Description
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