Comments (6)
@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.
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.
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.
@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.
@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.
from civet.
Would &: number + 1
or (&: number) + 1
be interesting typed shorthand for ($: number) => $ + 1
?
from civet.
Related Issues (20)
- `&` is not compiled to `$ => $` in specific contexts HOT 1
- `<` is weirdly sensitive to being less-than or extends in SAFE HOT 4
- Matching nested property with same name generates invalid JS
- Ampersand bugs HOT 1
- `.#x` shorthand for private properties HOT 1
- Missing parens in `.-1` access in certain contexts
- Attempted pattern matching ternary HOT 1
- Finishing civetconfig
- `get #x` requires newline, not semicolon HOT 1
- coffeeDo bug
- Use `{}` instead of `;` for empty block
- `for`/`else` HOT 2
- Generator operators
- Cannot shadow operator with argument HOT 1
- Sourcemaps are off when used with @propName HOT 1
- Add source location to error nodes
- `-o dist/.js` errors if the `dist` folder doesn't already exist HOT 2
- `-version` with only one hyphen throws a ReferenceError HOT 1
- "Invalid command-line argument" error includes stack dump
- Splice assignment with loop
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 civet.