From 103788b39d55dcf3f78705f8acbef789159edd38 Mon Sep 17 00:00:00 2001 From: Ville Saarinen Date: Wed, 24 Aug 2016 13:08:40 +0300 Subject: [PATCH] Add support for passing in undefined or null This is needed if strictNullChecks are enabled --- classnames/classnames-tests.ts | 8 +++++--- classnames/index.d.ts | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/classnames/classnames-tests.ts b/classnames/classnames-tests.ts index e296001ed8..5c99df82eb 100644 --- a/classnames/classnames-tests.ts +++ b/classnames/classnames-tests.ts @@ -17,6 +17,8 @@ classNames([{ foo: true, bar: false }, { baz: true }]); // => 'foo baz' classNames(["foo", ["bar", {baz: true}]]); // => 'foo bar baz' -// other falsy values are just ignored -// NOTE: We don't really want to allow this kind of thing with Typescript (otherwise what's the point!) -//classNames(null, false, 'bar', undefined, 0, 1, { baz: null }, ''); // => 'bar 1' \ No newline at end of file +// falsey values are just ignored +classNames(null, 'bar', undefined, 0, 1, { baz: null }, ''); // => 'bar 1' + +// Supporting booleans is tricky since we should only support passing in false, which is ignored +//classNames(false, 'bar', 0, 1, { baz: null }, ''); // => 'bar 1' diff --git a/classnames/index.d.ts b/classnames/index.d.ts index f9993f3c11..e6b645c5b0 100644 --- a/classnames/index.d.ts +++ b/classnames/index.d.ts @@ -3,7 +3,7 @@ // Definitions by: Dave Keen , Adi Dahiya , Jason Killian // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -declare type ClassValue = string | number | ClassDictionary | ClassArray; +declare type ClassValue = string | number | ClassDictionary | ClassArray | undefined | null; interface ClassDictionary { [id: string]: boolean;