Giter Club home page Giter Club logo

Comments (6)

STRd6 avatar STRd6 commented on May 26, 2024 2

@lorefnon TypeScript doesn't allow Type annotations on paren-less single parameters (another reason I choose to disallow them). There is definitely room to improve error messages in the LSP and I'd be happy for you to take a look.

The recommended Civet way to type annotate your example is:

z : (n: number) => number := &+1

Note the annotation is for the type of z to the left of the const assignment :=.

In cases where the ampersand function is used inline TS can usually infer the type correctly.

declare const x : number[]

y := x.map &+1

@edemaine in light of these examples I think that allowing inline type annotation of ampersand functions makes the intent a bit less clear but I'd be happy to look at some counter examples.

Also, I want to say thank you both for your contributions! It really helps me work out the practical details of the language to see how people feel most comfortable using it.

from civet.

STRd6 avatar STRd6 commented on May 26, 2024

I feel the "one arg optional parens" "feature" in ES is a design error. Civet also provides a better way to omit single arguments with the &+1 => $=>$+1 function shorthand.

You can use y := &+1 for your example above.

In cases where CoffeeScript did a feature earlier / better I prefer to use that design to "fix" things where ES left inconsistencies.

A lot of words to say this is by design but maybe a "civet esCompat" directive could include this for people who have a large legacy ES codebase to migrate.

from civet.

lorefnon avatar lorefnon commented on May 26, 2024

Ok, I'll close this since this design was intentionally chosen.

I can get used to always needing parenthesis for fn args.

The & syntax is not convenient other than places where the the type can be inferred because something like y := &+1 results in a ts error that the (mysterious 😄 ) parameter $ implicitly has an any type.

from civet.

STRd6 avatar STRd6 commented on May 26, 2024

@lorefnon Good point about the type inference. You could add a type annotation to the declaration side like: y : (n:number) => number := &+1 but I'm open to exploring a better way.

from civet.

lorefnon avatar lorefnon commented on May 26, 2024

@STRd6 I don't have a strong opinion/suggestion here, but I'll see if I can do something on the lsp side to make the error better. The current errors are not very obvious to someone who is not aware of the paramless arrow fn syntax.

image

from civet.

edemaine avatar edemaine commented on May 26, 2024

Would &: number + 1 or (&: number) + 1 be interesting typed shorthand for ($: number) => $ + 1?

from civet.

Related Issues (20)

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.