Skip to content
This repository has been archived by the owner on Jan 29, 2024. It is now read-only.

Types as comments syntax? #387

Open
piranna opened this issue Nov 26, 2023 · 1 comment
Open

Types as comments syntax? #387

piranna opened this issue Nov 26, 2023 · 1 comment

Comments

@piranna
Copy link

piranna commented Nov 26, 2023

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.

@piranna
Copy link
Author

piranna commented Jan 28, 2024

I have just discover this syntax and intention are pretty much similar to Flow inline comments, so I think it would be a nice addition :-)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant