Skip to content

Instantly share code, notes, and snippets.

@calebdwilliams
Created July 15, 2020 14:17
Show Gist options
  • Save calebdwilliams/d5ccdcc4aa8a190fd41cc8422af46305 to your computer and use it in GitHub Desktop.
Save calebdwilliams/d5ccdcc4aa8a190fd41cc8422af46305 to your computer and use it in GitHub Desktop.
Mixin annotation with JSDoc and TypeScript
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
*/
}