Open octogonz opened 5 years ago
Duplicate of https://github.com/microsoft/TypeScript/issues/31163 (except that issue only included methods).
Should that one be a dupe of this one then? :-P
I'll let the TypeScript devs decide ;)
Duplicate of #13199?
I am doing some documentation for a project written in typescript when I realized that most of the function return values in that project is inferred, so there is nothing I can copy-paste.
I can still hover the mouse over that function or whatsoever to copy the inferred type, but it is filled with ...
, and I can find nowhere to get the full inferred type.
Then I tried --declaration --emitDeclarationOnly
, but what I get is no more than ReturnType<typeof foo>
.
So, after so many issues related to that, how can I get the inferred type literal so that I can include them in docs ?
Search Terms
refactoring quick fix add inferred type
Suggestion
VS Code should provide a refactoring command for generating a type annotation.
Use Cases
In our code base, we use the TSLint's typedef rule to enforce type annotations. For example:
It's true that these types can usually be inferred by the compiler. However, requiring people to write explicit annotations makes code more readable, especially in situations where IntelliSense is unavailable. For example: When reviewing a GitHub pull request, or printing a Git history, we get no help from IntelliSense.
Details
VS Code should provide a refactoring command for generating a type annotation. For example, if I right-click on
map
in this code......then I should be able to do
Refactor -> Add Type
, and it will convert it to the good form shown above.Although this is a super easy operation for the compiler engine, I cannot seem to find an implementation of this feature.
I found a couple projects typescript-plugin-add-type and typescript-plugin-proactive-code-fixes. However, they aren't usable:
Representing refactoring operations as compiler plugins doesn't seem like the best design:
npm install
is in a good state, which is not always the case for a project that is "under construction"Since the implementation is relatively simple, this seems like a good candidate for a built-in feature.
Checklist
My suggestion meets these guidelines: