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

Is it possible to extend ProxyHandler interface? #3057

Open
ikabirov opened this issue Aug 22, 2018 · 3 comments
Open

Is it possible to extend ProxyHandler interface? #3057

ikabirov opened this issue Aug 22, 2018 · 3 comments

Comments

@ikabirov
Copy link
Contributor

I'll try to write externs for Record from Immutable.js.

When class contains only get method it's ok, but it's ignored when object contains custom methods

@brad4d
Copy link
Contributor

brad4d commented Aug 22, 2018

It looks like ProxyHandler is defined as an @record in es6_proxy.js, so it should be possible to extend it like this.

/**
 * @extends {ProxyHandler}
 * @record
 */
function MyProxyHandler() {}

/**
 * @param {number} n
 * @return {string}
 */
MyProxyHandler.prototype.myMethod = function(n) {};

What does your code look like?

@ikabirov
Copy link
Contributor Author

Extending ProxyHandler work only if we have no additional methods:

/**
 * @extends {ProxyHandler<T>}
 * @record
 * @template T
 */
function MyProxyHandler() {}

/**
 * @typedef {{
 *   src: string,
 * }}
 */
var MyData;

/**
 * @param {MyProxyHandler<MyData>} proxy
 */
function foo(proxy) {
	proxy.myMethod(1); // WARNING - Property myMethod never defined on MyProxyHandler
	console.log(proxy.src); // OK
}

But if we add custom method extending ProxyHandler does not work:

/**
 * @extends {ProxyHandler<T>}
 * @record
 * @template T
 */
function MyProxyHandler() {}

/**
 * @param {number} n
 * @return {string}
 */
MyProxyHandler.prototype.myMethod = function(n) {};

/**
 * @typedef {{
 *   src: string,
 * }}
 */
var MyData;

/**
 * @param {MyProxyHandler<MyData>} proxy
 */
function foo(proxy) {
	proxy.myMethod(1); // OK
	console.log(proxy.src); // WARNING - Property src never defined on MyProxyHandler
}

@brad4d
Copy link
Contributor

brad4d commented Aug 24, 2018

@ikabirov thanks for the detailed repro.
I've created an internal bug to track fixing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants