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 opened on 2024幎11月4日

GitHub で芋る
 (0 comments) (0 reactions) (0 assignees)TypeScript (6,726 forks)batch import
Experience EnhancementHelp WantedSuggestion

Repository metrics

Stars
 (48,455 stars)
PR merge metrics
 (平均マヌゞ 6d 17h) (30d で 9 merged PRs)

説明

🔍 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

コントリビュヌタヌガむド