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

Add typed return value from functions #325

Open
sparhami opened this issue Mar 21, 2017 · 0 comments
Open

Add typed return value from functions #325

sparhami opened this issue Mar 21, 2017 · 0 comments

Comments

@sparhami
Copy link
Contributor

We should add type information to returned elements where possible using goog.dom.TagName. For example, this might look like:

/**
 * @param {!goog.dom.TagName<T>|string} tagName
 * @return R
 * @template T
 * @template R := cond(isUnknown(T), 'Element', T) =:
 */
function open(tagName) {

}

This is may be more useful if we create bound element functions, where we can return the typed element in the callback. For example:

const TagName = goog.dom.TagName;
const div = function(config, cb) {
  open(TagName.DIV);
    cb(currentParent());
  close(TagName.DIV);
}

The usage would be:

div({...}, (el) => {
  // compiler knows el is an HTMLDivElement
});
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

1 participant