Closed abaksha-sc closed 2 years ago
Getter for defaultState cannot be defined with TypeScript. Example:
defaultState
class MyComponent extends HyperHTMLElement { get defaultState() { return { test: 123 }; } }
Following error appears:
'defaultState' is defined as a property in class 'HyperHTMLElement<{}>', but is overridden here in 'MyComponent' as an accessor.
I've created a minimal code here:
https://www.typescriptlang.org/play?#code/CYUwxgNghgTiAEkoGdnwBIE8AOIboBUBZAGQFEIQBbEAOwBcAeA+AXngG8BfAPk4Ch4Q5PSj0AlmHhwowAPa0ImeHIBGyPADcQwAIL16McaoCu9EMgBc8EUdoBzANoBdANyChYBbZNh6cmAAKAEp3IUQZc2AQ6005cWAwoTFDYzMQAGEACygHHQyoCAhVKDAAa0DaKBprW3EHABp4bDhNWtTGxBMYGHa7e2DY+MSPeBzaYEoybQZAkDb4abp6Qfg4hKSbUXNrAk2ZeUVlUAAzKBMIegBlbZBd-bpQINX1kfCNa9vAkTE7+AAFWASQrMPgAH3ggUC9Cy4is8BhcKaPx28AIwTYfEBMGBEFBwRew02KMk8FO9RAlWqfzqnTk2Ak3gA-NYKNRlgAREAneriRm0ADyDPE3kJG34XH4-CQqDRFno8BAAA9zBM0FhcPhiORKDQGAJwvB7CAFadzpcbr8QgbDeE4PRurROAj5dYAIwAJgAzPAuJtfRKgA
This is because defaultState is defined as just readonly property when it should be described as getter:
readonly
getter
declare class HyperHTMLElement<T = {}> { ... readonly defaultState: T; }
The solution is to change definition of defaultState to something like this:
declare class HyperHTMLElement<T = {}> { ... get defaultState(): T {} }
Fixed by PR: https://github.com/WebReflection/hyperHTML-Element/pull/78
Getter for
defaultState
cannot be defined with TypeScript. Example:Following error appears:
I've created a minimal code here:
https://www.typescriptlang.org/play?#code/CYUwxgNghgTiAEkoGdnwBIE8AOIboBUBZAGQFEIQBbEAOwBcAeA+AXngG8BfAPk4Ch4Q5PSj0AlmHhwowAPa0ImeHIBGyPADcQwAIL16McaoCu9EMgBc8EUdoBzANoBdANyChYBbZNh6cmAAKAEp3IUQZc2AQ6005cWAwoTFDYzMQAGEACygHHQyoCAhVKDAAa0DaKBprW3EHABp4bDhNWtTGxBMYGHa7e2DY+MSPeBzaYEoybQZAkDb4abp6Qfg4hKSbUXNrAk2ZeUVlUAAzKBMIegBlbZBd-bpQINX1kfCNa9vAkTE7+AAFWASQrMPgAH3ggUC9Cy4is8BhcKaPx28AIwTYfEBMGBEFBwRew02KMk8FO9RAlWqfzqnTk2Ak3gA-NYKNRlgAREAneriRm0ADyDPE3kJG34XH4-CQqDRFno8BAAA9zBM0FhcPhiORKDQGAJwvB7CAFadzpcbr8QgbDeE4PRurROAj5dYAIwAJgAzPAuJtfRKgA
This is because
defaultState
is defined as justreadonly
property when it should be described asgetter
:The solution is to change definition of
defaultState
to something like this: