Open bhavinkamani opened 7 years ago
this is what typescript compiles down to:
$ 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;
var z_1 = require("z");
var person = { name: 'Maria' };
z_1.matches(person)(function (x) {
if (x === void 0) { x = { name: 'John' }; }
return console.log('John you are not welcome!');
}, function (x) { return console.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.
Hi, i release a babel plugin to preserve the toString of transpiled arrow function, i tested in a project with z and it seems work babel-plugin-preserve-arrow-function-to-string.
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
.