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

use TS type guards over : boolean in type check functions (R.is, R.is[X]) #109

Closed
KiaraGrouwstra opened this issue Nov 20, 2016 · 4 comments

Comments

@KiaraGrouwstra
Copy link
Member

KiaraGrouwstra commented Nov 20, 2016

We now have e.g. is(ctor: any, val: any): boolean;, which the TS docs tell us we can further strengthen using type guards. Let's do that. :)

Edit: on second thought, I don't think at the type level we get enough information to better type the other is functions, beside the generic one...

@TylerYang
Copy link

TylerYang commented Dec 8, 2016

Could sombody take a look at this mr, please? I just meet a use case that might need to merge this mr,

function grepSomethingRecursively(grepPatterns: String | String[]) {
    if (R.is(Array, grepPatterns)) {
        R.forEach(doSomething, grepPatterns) 
        //throw exception: argument of type 'string | string[]' is not assignable to parameter of type 'string[]'.
    } else {
        ...
    }
}

R.forEach is required to take array as its parameters.
And with running R.is the type of grepPatterns cannot be inferred by the checker. So it throws an exception.

In contrast, the lodash works fine due to the definition.

@TylerYang
Copy link

Hi @tycho01 ,I just copy your mr and try to run with this function, it throws the exception also.

//throw exception: argument of type 'string | string[]' is not assignable to parameter of type 'string[]'.

KiaraGrouwstra added a commit to KiaraGrouwstra/typescript-ramda that referenced this issue Dec 8, 2016
@KiaraGrouwstra
Copy link
Member Author

@TylerYang: thanks for reporting this! I just merged in your use-case as a new test and implemented a fix.

@TylerYang
Copy link

NP : )

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

No branches or pull requests

2 participants