microsoft / microsoft/TypeScript
Type a standard import with jsdoc only
Personne n'a encore pris cette issue.
- Langage dominant
- Go
- Étoiles
- 111k
- Forks
- 14.4k
- Merge moyen
- 1 j 19 h
- PR mergées (30 j)
- 117
Description
🔍 Search Terms
ecmascript module import jsdoc
✅ Viability Checklist
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
- This isn't a request to add a new utility type: https://github.com/microsoft/TypeScript/wiki/No-New-Utility-Types
- This feature would agree with the rest of our Design Goals: https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals
⭐ Suggestion
Right now I can type an require call with
/**
* @type {typeof import("./accounts").userAccount}
*/
var x = require("./accounts").userAccount;
from https://www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html#import-types
But when I my code uses an import statement
import { shortNameFromImport } from "textmodule";
I did not found a way to type that when the module resolution does found a hit.
@type in the line before can not be used because there is no let or const in this line.
/** @type {import('textmodule')} */
import { shortNameFromImport } from "textmodule";
And the normal way to type a variable with parenthesis can not be used because it is not valid JS code:
import { /** @type {import('textmodule')} */ (shortNameFromImport ) } from "textmodule";
Both variants without parenthesis do not work...
import { /** @type {import('textmodule')} */ shortNameFromImport } from "textmodule";
import { shortNameFromImport /** @type {import('textmodule')} */ } from "textmodule";
📃 Motivating Example
With typescript code I can do some magic with path in the tsconfig.json
"paths": {
"textmodule": [ "./textmodule.ts" ]
},
But I wanted to have a JSDoc only solution.
💻 Use Cases
See above
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par la documentation des types pris en charge par JSDoc, en particulier la section import-types, et comparez son exemple de require avec les exemples d’importations nommées de cette issue. Suivez la manière dont le TypeScript checker traite JSDoc dans les déclarations d’importation JavaScript, puis définissez des tests pour l’annotation prise en charge et confirmez que la sortie JavaScript reste inchangée.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- javascript, typescript
- Domaine
- compilers
- Type d'issue
- Fonctionnalité
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 25/100