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)
- Pipe after implicit object is incorrect
- Trailing `or` on newline after callback function in implicit application parses as nested implicit function call instead of method body HOT 1
- bun + jsx syntax HOT 3
- vscode ext, add option to disable diagnostics HOT 1
- import extension gets rewritten but wrong HOT 1
- `[…asyncIterator]` sugar for `Array.fromAsync`? HOT 4
- `civet *.civet` file execution bug when reading config from any file
- import vs multiplication
- Indented chained ternarys fail to parse
- Array destructuring into @vars doesn't declare temporary variables HOT 1
- Problems with `node --test`s written in Civet (or possibly wider issue with ESM reading config)
- Generate normal `.d.ts` extension HOT 2
- Correctly load civet config file inner a workspace
- Solid Start file router
- Support for neovim/vim HOT 2
- `autoConst` not producing `const` HOT 1
- Nested type annotation fails to parse HOT 2
- VSCode Intellisense not working HOT 2
- Double inlay hints for .ts files HOT 1
- Optional `@?x` fails to parse HOT 5
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.