question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Typescript type annotations as comments

See original GitHub issue

Typescript’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:open
  • Created 7 years ago
  • Reactions:102
  • Comments:56 (24 by maintainers)

github_iconTop GitHub Comments

48reactions
abenhamdinecommented, Jan 12, 2017

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 :

  • the compilation step in Typescript is quite fast, simple and reliable
  • the js code generate is very readable. Actually, the code transpiled by Typescript is nearly the same that i would have written ! (minus some line breaks removed, etc…). It means that if you want, at any moment, you could stop using ts, and revert back to the js files.

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.

25reactions
mlegcommented, Nov 9, 2017

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found