Proposal static type constraints features

kdex kdex at kdex.de
Sun Jun 3 10:51:00 UTC 2018


`x = void([Number, mod.BigNumber])` is already valid syntax in ECMAScript, and 
you can't change its semantics willy-nilly. How do you guarantee that those 
who have used `void` in their code in the past don't suddenly see unexpected 
type errors?

Also, can you make an example of how you could assign a default value to `x` 
*and* support your type constraints? The problem that I see is that `void` 
already evaluates its argument to `undefined`, which means that you would be 
forced to do something like

```js
function CustomNumber(x = void([Number, mod.BigNumber]) || 42n) {
	// …
}
```

which is arguably awkward.

On Sunday, June 3, 2018 9:53:34 AM CEST 喻恒春 wrote:
> Hello all,
> 
> Sorry, I submitted a issue  on the tc39/proposals/issues/146. It seems to be
> a mistake.
 
> This proposal adds static type constraints features to ECMAScript, based on
> the existing syntax, just use the features of void.
 
> It is located in the variable initial value or declares the parameter
> default value or the first statement of the body of the function.
 
> 
> 
> 
> Example:  not all
> 
> 
> 
> 
> ```js
> 
> function CustomName(x = void ['', Number, mod.BigNumber]) {
> 
>   // Declarative results type, and the default value is not available
> 
>   void String;
> 
>   // same as void [String]
> 
>   // This function must eventually return a string
> 
>   // ...
> 
> }
> 
> 
> 
> 
> class CustomClass {
> 
>   // ...
> 
> }
> 
> 
> 
> 
> class PureStructure {
> 
>   constructor() {
> 
>     void {
> 
>       name: void [!'',String], // must be a name
> 
>       age: void [!0, Number], // must be age
> 
>       email: void String
> 
>     };
> 
>   }
> 
> }
> 
> 
> 
> 
> class ClassPrototype {
> 
>   constructor() {
> 
>     void {
> 
>       name: String,
> 
>       age: Number,
> 
>       email: String
> 
>     };
> 
>   }
> 
> }
> 
> 
> 
> 
> class FunctionPrototype {
> 
>   constructor() {
> 
>     void [[
> 
>       String,
> 
>       Number,
> 
>       String
> 
>     ]];
> 
>   }
> 
> 
> 
> }
> 
> ```
> 
> 
> 
> 
> Very embarrassing, my English is not awesome, so.........
> 
> 
> 
> 
> See https://github.com/achun/proposal-static-type-constraints-features
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180603/6f5784d7/attachment.sig>


More information about the es-discuss mailing list