Typing mixins does not work as mentioned in the docs
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 142
- Forks
- 230
- PR merge metrics
- No merged PRs in 30d
Description
Hello,
The documentation contains information on typing the subclass returned by a mixin: https://lit.dev/docs/composition/mixins/#typing-the-subclass
However, this does not seem to work in call instances: When you copy the example code into the playground: [link](https://lit.dev/playground/#project=W3sibmFtZSI6InNpbXBsZS1ncmVldGluZy50cyIsImNvbnRlbnQiOiJ0eXBlIENvbnN0cnVjdG9yPFQgPSB7fT4gPSBuZXcgKC4uLmFyZ3M6IGFueVtdKSA9PiBUO1xuaW1wb3J0IHtMaXRFbGVtZW50fSBmcm9tICdsaXQtZWxlbWVudCc7XG5cbmV4cG9ydCBkZWNsYXJlIGNsYXNzIE15TWl4aW5JbnRlcmZhY2Uge1xuICBoaWdobGlnaHQ6IGJvb2xlYW47XG4gIHByb3RlY3RlZCByZW5kZXJIaWdobGlnaHQoKTogdW5rbm93bjtcbn1cbuKAi1xuZXhwb3J0IGNvbnN0IE15TWl4aW4gPSA8VCBleHRlbmRzIENvbnN0cnVjdG9yPExpdEVsZW1lbnQ-PihzdXBlckNsYXNzOiBUKSA9PiB7XG4gIGNsYXNzIE15TWl4aW5DbGFzcyBleHRlbmRzIHN1cGVyQ2xhc3Mge1xuICAgIGhpZ2hsaWdodCA9IGZhbHNlO1xuICAgIHByb3RlY3RlZCByZW5kZXJIaWdobGlnaHQoKSB7XG4gICAgICAvKiAuLi4gKi9cbiAgICB9XG4gIH07XG4gIC8vIENhc3QgcmV0dXJuIHR5cGUgdG8geW91ciBtaXhpbidzIGludGVyZmFjZSBpbnRlcnNlY3RlZCB3aXRoIHRoZSBzdXBlckNsYXNzIHR5cGVcbiAgcmV0dXJuIE15TWl4aW5DbGFzcyBhcyBDb25zdHJ1Y3RvcjxNeU1peGluSW50ZXJmYWNlPiAmIFQ7XG59In0seyJuYW1lIjoiaW5kZXguaHRtbCIsImNvbnRlbnQiOiI8IURPQ1RZUEUgaHRtbD5cbjxoZWFkPlxuICA8c2NyaXB0IHR5cGU9XCJtb2R1bGVcIiBzcmM9XCIuL3NpbXBsZS1ncmVldGluZy5qc1wiPjwvc2NyaXB0PlxuPC9oZWFkPlxuPGJvZHk-XG4gIDxzaW1wbGUtZ3JlZXRpbmcgbmFtZT1cIldvcmxkXCI-PC9zaW1wbGUtZ3JlZXRpbmc-XG48L2JvZHk-XG4ifV0)
The compiler errors with something like `Conversion of type '{ new (...args: any[]): MyMixinClass; prototype: MyMixin.MyMixinClass; } & T' to type 'Constructor & T' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first. Type '{ new (...args: any[]): MyMixinClass; prototype: MyMixin.MyMixinClass; } & T' is not comparable to type 'Constructor'. Type 'MyMixinClass & LitElement' is not comparable to type 'MyMixinInterface'. Property 'renderHighlight' is protected but type 'MyMixinClass' is not a class derived from 'MyMixinInterface'.`.
Is it necessary to convert the class to `unknown` first maybe?
Thanks,
Christian
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the “Typing the subclass” example in the linked Lit documentation and reproduce it in the linked TypeScript playground. Compare the compiler error with the documented cast and determine whether the example or its explanation needs updating. Done means the example compiles as documented or clearly explains the required type conversion.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100