Microsoft/TypeScript

When using typeof for the interface, it is hoped that the jsdoc comments of the expression can inherit typeof by default

Open

#60.403 geöffnet am 4. Nov. 2024

Auf GitHub ansehen
 (0 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)TypeScript (6.726 Forks)batch import
Experience EnhancementHelp WantedSuggestion

Repository-Metriken

Stars
 (48.455 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 6T 17h) (9 gemergte PRs in 30 T)

Beschreibung

🔍 Search Terms

"typeof","jsdoc"

✅ Viability Checklist

⭐ Suggestion

/** JSDoc1 */
const test = { a: 0 }

declare module 'vue' {
  interface ComponentCustomProperties {
    /** JSDoc2 */
    testInInterface: typeof test,
  }
}

const test2 = {
  /** JSDoc3 */
  test
}

I hope that when not writing JSDoc2 or JSDoc3, testInInterface and test2.test can have comments for const test in JSDoc1

📃 Motivating Example

The interface has the feature of declaring and merging, allowing developers to extend the interfaces defined in the component library. In front-end development, extending Vue's global components, directives, and properties is often used.

Taking a Vue component as an example, including its global and local usage schemes, there is currently a lack of JSDoc comments

  • global
import vueComponentWithJsDoc from './test.vue'

declare module 'vue' {
  interface GlobalComponents {
    vueComponentWithoutJsDoc: typeof vueComponentWithJsDoc
  }
}
  • local
import vueComponentWithJsDoc from './test.vue'
import { defineComponent } from 'vue'

export default defineComponent({
  components: { vueComponentWithoutJsDoc: vueComponentWithJsDoc  }
})

When using components in the template, both of the above schemes lack JSDoc comments

<template>
  <vue-component-without-js-doc />
</template>

💻 Use Cases

  1. JSDoc comments can be included when declaring a merge interface
  2. The type obtained by the typeof instance is missing the jsdoc annotation
  3. Manually copy a jsdoc comment onto the interface field

Contributor Guide