Skip to content

Commit

Permalink
Add type refinement to Ramda #isNil. (flow-typed#1504)
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewSouthpaw authored and gantoine committed Nov 9, 2017
1 parent 6fd2ad7 commit 8f69fdb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
4 changes: 2 additions & 2 deletions definitions/npm/ramda_v0.x.x/flow_v0.49.x-/ramda_v0.x.x.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,8 @@ declare module ramda {
declare function type(x: ?any): string;
declare function isArrayLike(x: any): boolean;

declare function isNil(x: void | null): true;
declare function isNil(x: mixed): false;
declare function isNil(x: mixed): boolean %checks(x === undefined ||
x === null);

// *List
declare function adjust<T>(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
/* @flow */
/*eslint-disable no-undef, no-unused-vars, no-console*/
import _, { compose, pipe, curry, filter, find, repeat, zipWith } from "ramda";
import _, {
compose,
pipe,
curry,
filter,
find,
isNil,
repeat,
zipWith
} from "ramda";

const ns: Array<number> = [1, 2, 3, 4, 5];
const ss: Array<string> = ["one", "two", "three", "four"];
Expand Down Expand Up @@ -36,8 +45,15 @@ const str: string = "hello world";
//Type
{
const x: boolean = _.is(Number, 1);
const x1: false = _.isNil(1);
const x1a: true = _.isNil();
const x1b: true = _.isNil(null);
const x1: boolean = isNil(1);

// should refine type
const x1a: ?{ a: number } = { a: 1 };
//$ExpectError
x1a.a;
if (!isNil(x1a)) {
x1a.a;
}

const x2: boolean = _.propIs(1, "num", { num: 1 });
}

0 comments on commit 8f69fdb

Please sign in to comment.