Civet: -> doesn't work in interfaces

This works …

interface Cow
    type: 'cow'
    giveMilk : =>

… but this doesn’t:

interface Cow
    type: 'cow'
    giveMilk : ->

Shouldn’t it? I get:

/Users/zolo/project/program/test.civet:17:17 Failed to parse
Expected:
	TypeIndexSignature "readonly"
	DecimalBigIntegerLiteral /(?:0|[1-9](?:_[0-9]|[0-9])*)n/
	BinaryIntegerLiteral /0[bB][01](?:[01]|_[01])*n?/
	OctalIntegerLiteral /0[oO][0-7](?:[0-7]|_[0-7])*n?/
	HexIntegerLiteral /0[xX][0-9a-fA-F](?:[0-9a-fA-F]|_[0-9a-fA-F])*n?/
	DecimalLiteral /(?:0|[1-9](?:_[0-9]|[0-9])*)(?=\.(?:\p{ID_Start}|[_$]))/
	DecimalLiteral /(?:0|[1-9](?:_[0-9]|[0-9])*)(?:\.(?:[0-9](?:_[0-9]|[0-9])*))?/
	DecimalLiteral /(?:\.[0-9](?:_[0-9]|[0-9])*)/
Found: ">"
ts

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 15 (9 by maintainers)

Commits related to this issue

Most upvoted comments

It may not matter much either way. There is a subtle difference between method and arrow with --strictFunctionTypes but I don’t think we want to emphasize that. Maybe making -> always be => in types is the way to go (at least until a compelling reason otherwise emerges).

I was thinking that for classes and interfaces we should compile like so:

class Cow
  type: 'cow'
  giveMilk: ->

interface Cow
  type: 'cow'
  giveMilk: ->

interface Cow2
  type: 'cow'
  giveMilk: -> number

---

class Cow {
  type = "cow";
  giveMilk() {}
}

interface Cow {
  type: "cow"
  giveMilk(): void
}

interface Cow2 {
  type: "cow"
  giveMilk(): number
}