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
feat(types): update types for v7 #4186
base: master
Are you sure you want to change the base?
Conversation
I'm supportive of this PR in general, so that we can finally resolve #3598. If there are breakages then that's okay, as long as the breakages make sense. Here is a list of downstream breakages. Let's take some time to make sure these are all reasonable. |
Also: I'm wondering if it's about time we added some real TypeScript tests somewhere. Nothing too fancy, just something to confirm that the types compile the way we expect them to compile. A good place for this would probably the barrel |
matches v6 lwc/index types
…ne-core provides better v6 -> v7 compat
Any test written in TypeScript is implicitly a test of the types, as changing the types will cause the tests to fail. So, provided we write enough tests in TypeScript, we get type coverage for free. |
@wjhsf The challenge there is that, historically, we don't have any TS-based browser tests in this repo. All our Karma tests are in JS, and our Jest tests (which do use TS) don't use JSDOM or browser APIs. So for example, we're not testing this kind of code anywhere: export default class extends LightningElement {
static renderMode = 'light' // should fail TS
renderedCallback() {
this.doesNotExist = foo // should fail TS
this.setAttribute(123, false) // should fail TS
}
} I'm wondering if it would make sense to have a "hello world" Jest+JSDOM test in the |
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.
This is starting to look really good, but I have some suggestions before merging this:
- We need to have at least some minimal tests, preferably in the
lwc
package, that test the types our users are likely to use. - We should figure out some way to make
createElement("x-foo", { is: Foo }).bar
work (wherebar
is some@api
-decorated property). There has to be some TypeScript jujitsu that can accomplish this.
I added it under
✅ |
Details
Things that changed
lwc/index.js
just re-exports from@lwc/engine-dom
.lwc/index.d.ts
contains numerous outdated types. This removes them. Fixes Have thelwc
package directly export types from@lwc/engine-dom
#3598.experimentalDecorators
flag inplayground/tsconfig.json
and runyarn build
for both options.lwc/html
, that provides the correct types for HTML templates. Just import it once in your project (or add it to your tsconfig includes) to get HTML templates to be correctly typed.this.template.host
toHTMLElement
instead of the broaderElement
, since we know that this will always be true.WireAdapter
andWireAdapterConstructor
were generic when imported fromlwc
, but not when imported from@lwc/engine-core
. I updated the type definitions to be generic with defaults, so that both imports should continue to work unmodified.Things that might break
AKA things that I saw break in our nucleus downstreams.
import myComponent from './my-component.html'
)lwc/html
orlwc/@engine-dom/html
somewhere in your project.StringKeyedRecord
Record<string, any>
or something better.ContextValue
WireContextValue
, but it's really justRecord<string, any>
, so maybe use something better.ContextConsumer
WireContextConsumer
Contextualizer
WireContextProvider
createElement
HTMLElement & MyComponentApiDecoratedProps
. You have to define your own interface to get the@api
decorated props, because TypeScript can't detect that. (You can use your component class, but that includes all component andLightningElement
props, not just component@api
decorated props, so it's not ideal.)this.template
is possibly undefined?.
) or non-null assertion (!.
)ClassMemberDecoratorContext
(or other decorator type)Does this pull request introduce a breaking change?
Does this pull request introduce an observable change?
GUS work item