Typescript type annotations as comments
See original GitHub issueTypescript’s goal is simply be Javascript + Types.
There are many use cases where one might want to use the excellent typechecker but not really have any emit stage.
Projects already written in javascript work with allowJS. Typescript already supports parsing types from jsdoc comments.
What would be really awesome is just comment annotating your javascript with types and the project gets the benefit of being type checked. This could be a boon for a lot of existing javascript projects. Getting intellisense, VSCode typechecking on the fly and a lot of language server awesomeness.
e.g.
/// <reference path="..." />
class Hello {
/*:: private*/ hello(message /*: string*/) /*: Promise<{}>*/{
const promise /*: Promise<void>*/ = null
return /*:: <Promise<{}>>*/ null;
}
}
i.e
/: [type] */ /:: [tscode] */
Issue Analytics
- State:
- Created 7 years ago
- Reactions:102
- Comments:56 (24 by maintainers)
Top Results From Across the Web
Type annotations (aka, types as comments) - LogRocket Blog
Recently, a new ECMAScript proposal called type annotations (previously referred to as types as comments) was revealed.
Read more >Where is the syntax for TypeScript comments documented?
These type annotations are like the JSDoc comments found in the Closure system, but in TypeScript they are integrated directly into the language...
Read more >JSDoc Reference - TypeScript: Documentation
... using JSDoc annotations to provide type information in JavaScript files. ... can let users know by marking it with a /** @deprecated...
Read more >TC39 Proposal: Types as Comments
The Types as Comments proposal aims to simplify working in a modern JavaScript codebases. With Types as Comments, developers can remove a build...
Read more >Type Annotations in TypeScript - TekTutorialsHub
Typescript uses type annotation to specify the data type of the variable, function, object, or function return value.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
IMHO, I think this feature is not very necessary (and this is also for future readers who would were eagerly looking for this feature).
At the beginning, I was also shy to add a compilation step in our projects, and considered using Flow only for the benefit of comment syntax. But a few tries whith ts, I realized that :
Otherwise, you juste have to rename .js file to .ts file in order to have type checking.
FWIW, our project is a very complex application developped with node and extjs, and we migrate nearly 60% of server code to Typescript in 2 weeks.
Dear core typescript developers, thank you for such a high quality tool you made. But if you only could imagine how we, typescript users, desperately need the feature discussed… You’ve done so much and what’s left is so little.