Skip to content

type returns 'Object' for ES6 shorthand method declarations #32

@tidychips

Description

@tidychips

The type function returns 'Object' for ES6 method shorthand when running in an environment where that ES6 isn't transpiled. It's technically correct, but 'Function' seems like it would be more appropriate. This also makes isType and isFunction return unexpected results.

const obj = {
  f(){
    return 4;
  }
};

type(obj.f);  // => 'Object'
typeof obj.f; // => 'function'

It may also be worth considering that it produces the same result for computed property shorthand:

const name = 'f';
const obj = {
  [name](){
    return 4;
  }
};

type(obj.f);  // => 'Object'
typeof obj.f; // => 'function'

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions