lit / lit/lit.dev

Typing mixins with JSDoc

Open
#394 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
142
Forks
230
PR merge metrics
No merged PRs in 30d

Description

Consider having JSDoc examples for typing mixins. Something along the lines of the following has been working for me.

Create a dummy class that will be used as the interface:
```js
export class MyMixinInterface {
/** @returns {Promise} */
renderHighlight() {
return Promise.resolve();
}
}
```

And then use it in the mixin:

```js
/**
* @template TBase
* @param {TBase & {new (...args: any[]): LitElement}} baseElement will be the class from which it is extended
* @returns {TBase & {new (...args: any[]): import('./myMixinInterface').MyMixinInterface}} baseElement with mixins applied
*/
export const myMixin = (baseElement) => class extends baseElement {
renderHighlight() {
/* ... */
}
};
```

Hopefully I've not made any typos :-)

VSCode and TypeScript seems to work well. VSCode intellisense autocomplete being displayed and no TS warnings/errors.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Review the JSDoc mixin examples in the issue and inspect the repository's existing documentation entry points for the appropriate location. Done means the documentation includes a clear example of typing mixins and preserves the VSCode and TypeScript autocomplete and error-checking behavior described.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.