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 ouverte le 4 nov. 2024

Voir sur GitHub
 (0 commentaires) (0 réactions) (0 assignés)TypeScript (6 726 forks)batch import
Experience EnhancementHelp WantedSuggestion

Métriques du dépôt

Stars
 (48 455 stars)
Métriques de merge PR
 (Merge moyen 6j 17h) (9 PRs mergées en 30 j)

Description

🔍 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

Guide contributeur