Skip to content

[labs/context] @contextProvided doesn't work well with optional fields #3314

Closed

Description

@justinfagnani

Which package(s) are affected?

Context (@lit-labs/context)

Description

It's not possible to use optional fields with @contextProvided because of the use of Record in the decorator types.

This should work, since it's always possible that there is no provider for a context key:

const fooContext = createContext<Foo>('foo');

class MyElement extends LitElement {
  @contextProvided({context: fooContext})
  foo?: Foo;
}

Reproduction

See above

Workaround

Mark fields and context keys as X | undefined instead of optional.

Is this a regression?

No or unsure. This never worked, or I haven't tried before.

Affected versions

all

Browser/OS/Node environment

all

Activity

  1. moved this to 📋 Triaged in Lit Project Boardon Sep 28, 2022
  2. Repository owner moved this from 📋 Triaged to ✅ Done in Lit Project Boardon Nov 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions