Summary: You need to use a type guard when narrowing types in a filter. Reviewed By: danielbuechele Differential Revision: D17163782 fbshipit-source-id: aa78bdd392653ebf1080a04e62e131b607e5181b
13 lines
397 B
TypeScript
13 lines
397 B
TypeScript
/**
|
|
* Copyright 2018-present Facebook.
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
* @format
|
|
*/
|
|
|
|
// Typescript doesn't know Array.filter(Boolean) won't contain nulls.
|
|
// So use Array.filter(notNull) instead.
|
|
export function notNull<T>(x: T | null | undefined): x is T {
|
|
return x !== null && x !== undefined;
|
|
}
|