@@ -29,7 +29,7 @@ impl Foo {
2929
3030## Conversion operator
3131
32- Should happens between nonminal types.
32+ Should happens between nominal types.
3333
3434``` ts
3535let foo = Foo {} as Bar
@@ -87,8 +87,6 @@ It should offer benefits:
8787- If each unit type is nominal, we will have ` m*m ` conversion explosion.
8888- Another way is extension upon the data type, but it's just a problem of form.
8989
90-
91-
9290``` ts
9391let foo = 360deg
9492let bar = 6.28rad // for literal
@@ -160,3 +158,54 @@ type Foo = {
160158}
161159type Bar = Foo with { foo: double , baz: any } // [!code highlight]
162160` ` `
161+
162+ ## Constant members
163+
164+ Constants as special members, including functions and fields.
165+
166+ ` ` ` ts
167+ // should be evaluated at compile-time
168+ function foo(): const string { // implies the function returns const
169+ return " I am an constant"
170+ }
171+
172+ type Foo {
173+ foo: const string = foo () // only constant can be assigned from an constant generator function
174+ bar : const string = " I am also an constant"
175+ fn = (): const string => " foo"
176+ }
177+
178+ _ = Foo ::foo // use :: to access constant members
179+ _ = Foo ::fn () // this evaluates to an constant too
180+
181+ ```
182+
183+ ### Reflection constants
184+
185+ Some reflection properties should be just constants.
186+ Any type should have some default constant members like ` name ` , ` fullName ` , ` namespace ` (if we do plan to design the module system like this)
187+ Which means they're preserved constants.
188+
189+ ``` ts
190+
191+ type Bar {
192+ typeName: any // preserved member name can not be set // [!code error]
193+ }
194+ // Use `::` as constant accessor.
195+ _ = Foo ::typeName // -> `Foo`
196+ _ = Bar ::name
197+ ```
198+
199+ ## Default parameter mutation
200+
201+ ``` ts
202+ type Person {
203+ name: string
204+ age: uint
205+ }
206+ function foo(arg : Person = { name = " John" , age = 18 }): void {
207+
208+ }
209+ // use `default` to represent the default value of the parameter
210+ foo (default with { name = " jane" })
211+ ```
0 commit comments