Skip to content

Not possible to expose a getter with @Method #230

@mortenson

Description

@mortenson

Resources:
Before submitting an issue, please consult our docs.

Stencil version: (run npm list @stencil/core from a terminal/cmd prompt and paste output below):

$ npm list @stencil/core
my-name@0.0.1 /Users/samuelmortenson/repos/stencil-getter
└── @stencil/core@0.0.6-10

I'm submitting a ... (check one with "x")
[x] bug report
[ ] feature request
[ ] support request => Please do not submit support requests here, use one of these channels: https://forum.ionicframework.com/ or https://stencil-worldwide.slack.com

Current behavior:
If you add a @Method to a component and use the get keyword in front of the function name, the component will compile incorrectly leading to a Uncaught ReferenceError: Method is not defined error when loaded in a web browser.

Expected behavior:
I would expect that Stencil elements could expose getter/setter methods using @Method. These accessors are super useful, especially when trying to emulate the behavior of something like the <input> element's "value" attribute. It can get set as an initial property, and the attribute never changes in the DOM, but when input.value is called the current value is returned. Would be great to do something similar in Stencil.

Steps to reproduce:

  1. git clone git@github.com:mortenson/stencil-getter.git
  2. cd stencil-getter && npm install && npm start

See Uncaught ReferenceError: Method is not defined in your web browser.

Related code:

Here's the syntax I would expect to expose a getter/setter:

  @Method()
  get value() {
    return Math.random();
  }

(ref https://github.com/mortenson/stencil-getter/blob/master/src/components/my-name/my-name.tsx#L12)

Other information:

Here's the TypeScript documentation on Accessors (get/set): https://www.typescriptlang.org/docs/handbook/classes.html#accessors

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions