Created
July 15, 2020 14:17
-
-
Save calebdwilliams/d5ccdcc4aa8a190fd41cc8422af46305 to your computer and use it in GitHub Desktop.
Mixin annotation with JSDoc and TypeScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { LitElement } from 'https://cdn.pika.dev/lit-element@^2.3.1'; | |
/** @typedef {new (...args: any[]) => any} Constructor */ | |
/** | |
* @template {!Constructor} T | |
* @param {T} superclass - The class to extend | |
*/ | |
const FormControlMixin = (superclass) => | |
class FormControl extends superclass { | |
/** @type {boolean} */ | |
get checkValidity() { | |
return /* some magic */ | |
} | |
} | |
/** | |
* @template FormControlMixin, LitElement | |
*/ | |
class MyInput extends FormControlMixin(LitElement) { | |
/** | |
* TypeScript now recognizes this has checkValidity | |
* as well as all of LitElement's classes | |
*/ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Got help from https://discord.com/channels/508357248330760243/885523496329949245/933592504266260500
Checkout https://www.typescriptlang.org/play?filetype=js#code/PQKhCgAIUgBAXAngBwKYBNUDNIG8B2qA7pABQB0lAhgE4DmAzgFyRX6IDaAugJSQC8APjwBfEZADCAe3wN4NAK4BjeFQBGAG1RQQwcOFARoceKgC2yDVVN5ps+ctWbU4gCo64tOpABCVBqh4riI6elgK+CoAljKQAOKo+Jg0ALJRAB5R+KR+ATy4UJBFNKjwCjT4kEpWDAzxicmQqOmmSXW5qAVF3d10pQlJqDSk+SE9ISGGHgjmltaBuHZyiirqWm7TXr7+C8Gh4OGR8DGVAHJUZqhpmdkd+YXFpeWV1f5155dNLQ3tO109vVKH1QI1wY26EwMYGmpgsVhsixky0caxckHcxlgWw6QTGugOEWisQAgn1rlkcjt7j0SmUKlUanVSYFmq10L8Av8AZA+vBmaDwUVIeBXrVIABlMqYfDwL5splkjIU4Hk7IDZKq0iiupgnh6rk80rgERAA