Comments (12)
Even better: you could make it only parse comments which start //⚙️
.
More seriously, I'm definitely interested in this project and thought immediately of comments-as-types, because I've developed the habit of doing exactly that in my Node code already, like so:
// add :: number -> number -> number
const add = (a, b) => a + b;
//⚙️ add :: number -> number -> number
const add = (a, b) => a + b;
is probably not the best option, but something like it is a great idea.
from gear.
Good point. I actually like to write those comments as well when not using gear (I don't use it for any critical code).
What I am concerned about:
One could of course parse the comments, but I wouldn't want to do any strict type checking with this information, since it's still comments and comments should not be able to break the build.
But maybe I am thinking too conservatively here... 😅
My favorite compromise would be using decorators for the type annotations, but as long as node does not support them out of the box we would still need to transpile everything...
from gear.
I am going to bed now and will give it some time to sink in. We can use this issue for further brain storming!
from gear.
it's still comments and comments should not be able to break the build.
I guess that's true, although adding this comment to the top of a file can break a build: 😜
// @flow
from gear.
But seriously though, the idea of being able to type-check existing JS codebases that have hindley-milner style comments would be amazing.
from gear.
😅
After sleeping a night about it my biggest concern is defining complex types/shapes. I need to pass complex objects quite a lot:
// getUser :: string => User
function getUser (name) { ... }
I don't want to define those types in more comments... 🙃
Flow's type User = { ... }
definitions seem to be the right way to go.
from gear.
Yeah, I could see that. It would be fairly unpleasant to do this:
// type User = {
// name: string,
// age: number
// }
// getUser :: string => User
function getUser (name) {}
from gear.
Another possible notation:
/**
* In case you want to describe the function some more.
* @type {string => User}
* @see http://example.com/api/getUser
*/
function getUser (name) {}
But still does not solve the type User = { }
issue...
from gear.
@andywer I've thought a lot about how neat it would be to convert JSDoc annotations to Flow. Seems kind of like what you're getting at here, but you're right that it doesn't solve the ADT issue very cleanly.
from gear.
This is interesting! https://twitter.com/thejameskyle/status/868148120504356864
Maybe this is the solution to all this and makes gear
superfluous after all :)
from gear.
This is interesting, too: https://github.com/origamitower/metamagical
from gear.
It is. They just don't have type checking as it seems. Maybe if there was a babel plugin to transform their comments into flow type annotations or so... 🤔
from gear.
Related Issues (2)
- Project Status HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gear.