Coder Social home page Coder Social logo

Comments (12)

chriskrycho avatar chriskrycho commented on May 30, 2024

Even better: you could make it only parse comments which start //⚙️. :trollface:

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.

andywer avatar andywer commented on May 30, 2024

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.

andywer avatar andywer commented on May 30, 2024

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.

bmakuh avatar bmakuh commented on May 30, 2024

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.

bmakuh avatar bmakuh commented on May 30, 2024

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.

andywer avatar andywer commented on May 30, 2024

😅

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.

bmakuh avatar bmakuh commented on May 30, 2024

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.

andywer avatar andywer commented on May 30, 2024

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.

bmakuh avatar bmakuh commented on May 30, 2024

@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.

andywer avatar andywer commented on May 30, 2024

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.

bmakuh avatar bmakuh commented on May 30, 2024

This is interesting, too: https://github.com/origamitower/metamagical

from gear.

andywer avatar andywer commented on May 30, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.