Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

does not work with typescript #35

Open
bhavinkamani opened this issue Dec 1, 2017 · 3 comments
Open

does not work with typescript #35

bhavinkamani opened this issue Dec 1, 2017 · 3 comments

Comments

@bhavinkamani
Copy link

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';

const person = { 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.

@mindreframer
Copy link

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!"); });

@rnsell
Copy link

rnsell commented Aug 3, 2018

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.

@alfredosalzillo
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants