-
-
Notifications
You must be signed in to change notification settings - Fork 60
Types as comments syntax? #387
Description
Hegel inference system is really powerful, so types are usually not needed, but some times they are. For that, a Typescript / Flow syntax is being used, that later needs to be removed. In the same spirit of type annotations proposal where types syntax should be treated as comments by Javascript runtimes so there's no need of transpilation, what about if we add a comments-based syntax so we don't need it either? Two options I find here are respect JsDocs when they are defined, that are pretty common but verbose, or allow to use inline comments. This can be verbose too, so to minimize them, I propose to use inline comments, and consider them Hegel types if the first token inside the comment would be a valid Hegel type token:
const num /*:number*/ = 42;
function func(a/*:number*/, b/*:number*/)/*:number*/
{
return a + b
}
/*
type A
{
name: string
}
*/
class B /*implements A*/{}Syntax would need to be developed in more detail, but you get the idea, and I think that would be the most minimal solution.