-
Notifications
You must be signed in to change notification settings - Fork 1k
[context] Broaden the host type of context controllers to be compatible with Lit 2 #4287
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
🦋 Changeset detectedLatest commit: 6bb47e2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
📊 Tachometer Benchmark ResultsSummarynop-update
render
update
update-reflect
Resultsthis-change
render
update
update-reflect
this-change, tip-of-tree, previous-release
render
update
nop-update
this-change, tip-of-tree, previous-release
render
update
this-change, tip-of-tree, previous-release
render
update
update-reflect
|
|
The size of lit-html.js and lit-core.min.js are as expected. |
|
So the type errors the first commit creates look like this: Click to see the build output> @lit/context@1.0.0 build:ts:lit2-tests
> wireit
src/lib/decorators/consume.ts:57:29 - error TS2769: No overload matches this call.
Overload 1 of 2, '(host: ReactiveElement, options: Options<{ __context__: ValueType; }>): ContextConsumer<{ __context__: ValueType; }, ReactiveElement>', gave the following error.
Argument of type 'import("/Users/justinfagnani/Projects/Lit/lit-monorepo/packages/reactive-element/development/reactive-element", { assert: { "resolution-mode": "import" } }).ReactiveElement' is not assignable to parameter of type 'import("/Users/justinfagnani/Projects/Lit/lit-monorepo/node_modules/lit2/node_modules/@lit/reactive-element/development/reactive-element", { assert: { "resolution-mode": "import" } }).ReactiveElement'.
Overload 2 of 2, '(host: ReactiveElement, context: { __context__: unknown; }, callback?: ((value: unknown, dispose?: (() => void) | undefined) => void) | undefined, subscribe?: boolean | undefined): ContextConsumer<...>', gave the following error.
Argument of type 'import("/Users/justinfagnani/Projects/Lit/lit-monorepo/packages/reactive-element/development/reactive-element", { assert: { "resolution-mode": "import" } }).ReactiveElement' is not assignable to parameter of type 'import("/Users/justinfagnani/Projects/Lit/lit-monorepo/node_modules/lit2/node_modules/@lit/reactive-element/development/reactive-element", { assert: { "resolution-mode": "import" } }).ReactiveElement'.
57 new ContextConsumer(this, {
~~~~
src/lib/decorators/consume.ts:70:31 - error TS2769: No overload matches this call.
Overload 1 of 2, '(host: ReactiveElement, options: Options<{ __context__: ValueType; }>): ContextConsumer<{ __context__: ValueType; }, ReactiveElement>', gave the following error.
Argument of type 'import("/Users/justinfagnani/Projects/Lit/lit-monorepo/packages/reactive-element/development/reactive-element", { assert: { "resolution-mode": "import" } }).ReactiveElement' is not assignable to parameter of type 'import("/Users/justinfagnani/Projects/Lit/lit-monorepo/node_modules/lit2/node_modules/@lit/reactive-element/development/reactive-element", { assert: { "resolution-mode": "import" } }).ReactiveElement'.
Overload 2 of 2, '(host: ReactiveElement, context: { __context__: unknown; }, callback?: ((value: unknown, dispose?: (() => void) | undefined) => void) | undefined, subscribe?: boolean | undefined): ContextConsumer<...>', gave the following error.
Argument of type 'import("/Users/justinfagnani/Projects/Lit/lit-monorepo/packages/reactive-element/development/reactive-element", { assert: { "resolution-mode": "import" } }).ReactiveElement' is not assignable to parameter of type 'import("/Users/justinfagnani/Projects/Lit/lit-monorepo/node_modules/lit2/node_modules/@lit/reactive-element/development/reactive-element", { assert: { "resolution-mode": "import" } }).ReactiveElement'.
70 new ContextConsumer(element, {
~~~~~~~
src/lib/decorators/provide.ts:62:53 - error TS2769: No overload matches this call.
Overload 1 of 2, '(host: ReactiveElement, options: Options<{ __context__: ValueType; }>): ContextProvider<{ __context__: ValueType; }>', gave the following error.
Argument of type 'import("/Users/justinfagnani/Projects/Lit/lit-monorepo/packages/reactive-element/development/reactive-element", { assert: { "resolution-mode": "import" } }).ReactiveElement' is not assignable to parameter of type 'import("/Users/justinfagnani/Projects/Lit/lit-monorepo/node_modules/lit2/node_modules/@lit/reactive-element/development/reactive-element", { assert: { "resolution-mode": "import" } }).ReactiveElement'.
Types of property 'renderRoot' are incompatible.
Type 'DocumentFragment | HTMLElement' is not assignable to type 'ShadowRoot | HTMLElement'.
Type 'DocumentFragment' is not assignable to type 'ShadowRoot | HTMLElement'.
Type 'DocumentFragment' is missing the following properties from type 'ShadowRoot': delegatesFocus, host, mode, onslotchange, and 11 more.
Overload 2 of 2, '(host: ReactiveElement, context: { __context__: unknown; }, initialValue?: unknown): ContextProvider<{ __context__: unknown; }>', gave the following error.
Argument of type 'import("/Users/justinfagnani/Projects/Lit/lit-monorepo/packages/reactive-element/development/reactive-element", { assert: { "resolution-mode": "import" } }).ReactiveElement' is not assignable to parameter of type 'import("/Users/justinfagnani/Projects/Lit/lit-monorepo/node_modules/lit2/node_modules/@lit/reactive-element/development/reactive-element", { assert: { "resolution-mode": "import" } }).ReactiveElement'.
62 controllerMap.set(this, new ContextProvider(this, {context}));
~~~~
src/lib/decorators/provide.ts:81:58 - error TS2769: No overload matches this call.
Overload 1 of 2, '(host: ReactiveElement, options: Options<{ __context__: ValueType; }>): ContextProvider<{ __context__: ValueType; }>', gave the following error.
Argument of type 'import("/Users/justinfagnani/Projects/Lit/lit-monorepo/packages/reactive-element/development/reactive-element", { assert: { "resolution-mode": "import" } }).ReactiveElement' is not assignable to parameter of type 'import("/Users/justinfagnani/Projects/Lit/lit-monorepo/node_modules/lit2/node_modules/@lit/reactive-element/development/reactive-element", { assert: { "resolution-mode": "import" } }).ReactiveElement'.
Overload 2 of 2, '(host: ReactiveElement, context: { __context__: unknown; }, initialValue?: unknown): ContextProvider<{ __context__: unknown; }>', gave the following error.
Argument of type 'import("/Users/justinfagnani/Projects/Lit/lit-monorepo/packages/reactive-element/development/reactive-element", { assert: { "resolution-mode": "import" } }).ReactiveElement' is not assignable to parameter of type 'import("/Users/justinfagnani/Projects/Lit/lit-monorepo/node_modules/lit2/node_modules/@lit/reactive-element/development/reactive-element", { assert: { "resolution-mode": "import" } }).ReactiveElement'.
81 controllerMap.set(element, new ContextProvider(element, {context}));
~~~~~~~
Found 4 errors in 2 files.
Errors Files
2 src/lib/decorators/consume.ts:57
2 src/lib/decorators/provide.ts:62Notice that the errors are in the definitions of the decorators, not at the use site of the decorators. This is a bit unexpected to me, since the decorators accept a |
|
With the help of @rictic yesterday we figure out the the error I hit on lit.dev only occurs when you have an installation like: So the use site (top-level) is using If you swap the versions so that context is using 2.0 and the use site is using 1.6, then it type-checks fine because ShadowRoot is assignable to DocumentFragment. Testing context with a different version for the test code is relatively easy - it's just a new tsconfig for tests - testing with a different version for context itself is hard because you need to get the build of the tests to resolve I don't know how worth it it is to include a test like this. This is probably a corner case on installation, and there's an available if sometimes cumbersome fix of deduping npm installations. We could apply the fix and just not include these tests, and repeat if we get reports of similar errors externally. |
I agree with this sentiment. |
rictic
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that the tests are written, I think we should keep them.
I get the argument for not going to the bother to write them for some other less used packages though
| [K in keyof T]: T[K]; | ||
| }; | ||
|
|
||
| type ReactiveElementHost = Interface<Omit<ReactiveElement, 'renderRoot'>>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason why this can't also just be ReactiveContorllerHost & HTMLElement like for the ContextConsumer? Or maybe the other way around to use this for ContextConsumer?
Also wdyt about upstreaming this type into reactive-element so other decorators can use it too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ReactiveContorllerHost & HTMLElement works
Co-authored-by: Augustine Kim <[email protected]>
This adds
lit@^2.7.5and@lit/reactive-element@^1.6.2as dependencies of context, and builds the tests with those packages mapped in in a separate tsconfig.That highlighted the type error in the controllers, which I fixed by changing the host type to
ReactiveControllerHost & HTMLElement.