
Description
TypeScript Version: 2.1.0 / nightly (2.1.0-dev.20160916)
Code
// A *self-contained* demonstration of the problem follows...
//MyProject/src/foo.ts:
function foo(obj) {
var proxy = new Proxy(obj, {
has: function (target, propKey) {
return Reflect.has(target, propKey); // <- line 6
}
});
return proxy;
}
Expected behavior:
Should compile without error
Actual behavior:
tsc -p src
src/foo.ts(6,34): error TS2345: Argument of type 'PropertyKey' is not assignable to parameter of type 'symbol'.
Type 'string' is not assignable to type 'symbol'.
Current source code observation
//Currently TypeScript/src/lib/es2015.reflect.d.td:
declare namespace Reflect {
function apply(target: Function, thisArgument: any, argumentsList: ArrayLike<any>): any;
function construct(target: Function, argumentsList: ArrayLike<any>, newTarget?: any): any;
function defineProperty(target: any, propertyKey: PropertyKey, attributes: PropertyDescriptor): boolean;
function deleteProperty(target: any, propertyKey: PropertyKey): boolean;
function get(target: any, propertyKey: PropertyKey, receiver?: any): any;
function getOwnPropertyDescriptor(target: any, propertyKey: PropertyKey): PropertyDescriptor;
function getPrototypeOf(target: any): any;
function has(target: any, propertyKey: string): boolean; // <- line 9
function has(target: any, propertyKey: symbol): boolean; // <- line 10
function isExtensible(target: any): boolean;
function ownKeys(target: any): Array<PropertyKey>;
function preventExtensions(target: any): boolean;
function set(target: any, propertyKey: PropertyKey, value: any, receiver?: any): boolean;
function setPrototypeOf(target: any, proto: any): boolean;
}
//Currently TypeScript/src/lib/es2015.proxy.d.td:
interface ProxyHandler<T> {
getPrototypeOf? (target: T): any;
setPrototypeOf? (target: T, v: any): boolean;
isExtensible? (target: T): boolean;
preventExtensions? (target: T): boolean;
getOwnPropertyDescriptor? (target: T, p: PropertyKey): PropertyDescriptor;
has? (target: T, p: PropertyKey): boolean;; // <- ominous
get? (target: T, p: PropertyKey, receiver: any): any;
set? (target: T, p: PropertyKey, value: any, receiver: any): boolean;
deleteProperty? (target: T, p: PropertyKey): boolean;
defineProperty? (target: T, p: PropertyKey, attributes: PropertyDescriptor): boolean;
enumerate? (target: T): PropertyKey[];
ownKeys? (target: T): PropertyKey[];
apply? (target: T, thisArg: any, argArray?: any): any;
construct? (target: T, thisArg: any, argArray?: any): any;
}
interface ProxyConstructor {
revocable<T>(target: T, handler: ProxyHandler<T>): { proxy: T; revoke: () => void; };
new <T>(target: T, handler: ProxyHandler<T>): T
}
declare var Proxy: ProxyConstructor;
Easy Fix.
Replace lines 9 and 10 of TypeScript/src/lib/es2015.reflect.d.td with just:
function has(target: any, propertyKey: PropertyKey): boolean; // <- new line 9, delete old line 10
Also it would be nice if the method signatures in es2015.reflect.d.td followed the same order of declaration as in es2015.proxy.d.td which in turn followed the same order of mention in the ECMAScript ES2015 specification.
I would normally offer a patch/PR but such a small change is significantly outweighed by the burden of going through the new contributor process at this stage. So if somebody there doesn't mind ... Thanks.