escalier-lang / escalier-next

Improved type safety with tight TypeScript interop
https://escalier-lang.github.io/escalier-next/
MIT License
14 stars 0 forks source link

Idea for primary constructor in classes #306

Open kevinbarabash opened 4 months ago

kevinbarabash commented 4 months ago
class Foo(x, y) {
    x: number = x
    y: number = y

    // optional initializer
    init(self) {
       // self.x and self.y will be guaranteed to be initialized by this point
       // do something self.x or self.y
    }
}

This syntax is similar to public class fields but gets rid of the explicit constructor() and replaces it with the ability for the class to have a param list itself.

References: