Skip to content

[labs/context] Context decorators error on private or protected fields #3883

@justinfagnani

Description

@justinfagnani

Discussed in #3875

Originally posted by NealRame May 4, 2023
In my component I want to add a context properties which is also private

@provide({ context: someContext })
@state()
private _someData = 0

I read in the documentation that it is possible however when doing so, I get that typescript compiler error :

error TS2345: Argument of type 'MyComponent' is not assignable to parameter of type 'ReactiveElement & Record<"_someData", number>'.
  Type 'MyComponent' is not assignable to type 'Record<"_someData", number>'.
    Property '_someData' is private in type 'MyComponent' but not in type 'Record<"_someData", number>'.

89     @provide({ context: someContext })

Could someone explain me if I am missing something please?

I am using lit@2.6.1 and @lit-labs/context@0.3.1.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    ✅ Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions