You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Strange but when I use some of the snippets with typescript, it always returns the result of the first param. For example
import{matches}from'z';constperson={name: 'Maria'}matches(person)((x={name: 'John'})=>console.log('John you are not welcome!'),(x)=>console.log(`Hey ${x.name}, you are welcome!`))
returns John you are not welcome.
The text was updated successfully, but these errors were encountered:
$ mkdir ztypescripttest && cd ztypescripttest
$ yarn init -y
$ yarn add z typescript
$ vim index.ts # paste the example from above
$ ./node_modules/.bin/tsc index.ts
$ cat index.js
"use strict";exports.__esModule=true;varz_1=require("z");varperson={name: 'Maria'};z_1.matches(person)(function(x){if(x===void0){x={name: 'John'};}returnconsole.log('John you are not welcome!');},function(x){returnconsole.log("Hey "+x.name+", you are welcome!");});
Z uses a module to get meta data about functions, specifically information about default params. It then uses the reflection meta data to choose which function to run. If any code is transpiled to es5 the es6 code default assignements are removed from the function signature thus resulting in broken code. The above code needs to transpile to es6 or higher to work properly. This probably also means z pattern matching will break on babel transpiled code to es5.
Strange but when I use some of the snippets with typescript, it always returns the result of the first param. For example
returns
John you are not welcome
.The text was updated successfully, but these errors were encountered: