From 57efe44759f84b89f30ad3049d72ed40edd59edf Mon Sep 17 00:00:00 2001 From: Eli White Date: Thu, 5 Dec 2019 15:58:55 -0800 Subject: [PATCH] Move flow definitions to react-native Summary: These definitions make these libraries act as flow strict. We have them internally but need them in react native to be able to make files in react native flow strict. Internally our flowconfig includes all the configs in react-native-github. Changelog: [Internal]: Add flow strict type definitions for modules Reviewed By: zackargyle Differential Revision: D18839594 fbshipit-source-id: d523e15f00a9cfa66d3789bb249655bcbe6d04eb --- flow/fbjs.js | 258 +++++++++++++++++++++++++++++++++++++++ flow/use-subscription.js | 19 +++ 2 files changed, 277 insertions(+) create mode 100644 flow/fbjs.js create mode 100644 flow/use-subscription.js diff --git a/flow/fbjs.js b/flow/fbjs.js new file mode 100644 index 00000000000..15f3e0d3995 --- /dev/null +++ b/flow/fbjs.js @@ -0,0 +1,258 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @flow strict + * @format + * @nolint + */ + +declare module 'fbjs/lib/countDistinct' { + declare module.exports: {| + (iter: Iterable, selector: (item: T1) => T2): number, + |}; +} + +declare module 'fbjs/lib/warning' { + declare module.exports: {| + (condition: mixed, format: string, ...args: $ReadOnlyArray): void, + |}; +} + +declare module 'fbjs/lib/shallowEqual' { + declare module.exports: {| + (objA: mixed, objB: mixed): boolean, + |}; +} + +declare module 'fbjs/lib/EventListener' { + declare module.exports: {| + listen( + target: EventTarget, + eventType: string, + callback: any, + ): {remove(): void, ...}, + capture( + target: EventTarget, + eventType: string, + callback: any, + ): {remove(): void, ...}, + |}; +} + +declare module 'fbjs/lib/ExecutionEnvironment' { + declare module.exports: {| + +canUseDOM: boolean, + +canUseWorkers: boolean, + +canUseEventListeners: boolean, + +canUseViewport: boolean, + +isInWorker: boolean, + |}; +} + +declare module 'fbjs/lib/UserAgentData' { + declare module.exports: {| + +browserArchitecture: string, + +browserFullVersion: string, + +browserMinorVersion: string, + +browserName: string, + +browserVersion: string, + +deviceName: string, + +engineName: string, + +engineVersion: string, + +platformArchitecture: string, + +platformName: string, + +platformVersion: string, + +platformFullVersion: string, + |}; +} + +declare module 'fbjs/lib/VersionRange' { + declare module.exports: {| + contains(range: string, version: string): boolean, + |}; +} + +declare module 'fbjs/lib/base62' { + declare module.exports: {| + (number: number): string, + |}; +} + +declare module 'fbjs/lib/compactArray' { + declare module.exports: {| + (array: Array): Array, + |}; +} + +declare module 'fbjs/lib/concatAllArray' { + declare module.exports: any; +} + +declare module 'fbjs/lib/crc32' { + declare module.exports: {| + (str: string): number, + |}; +} + +declare module 'fbjs/lib/distinctArray' { + declare module.exports: {| + (xs: Iterable): Array, + |}; +} + +declare module 'fbjs/lib/emptyObject' { + declare module.exports: {||}; +} + +declare module 'fbjs/lib/equalsSet' { + declare module.exports: {| + (one: Set, two: Set): boolean, + |}; +} + +declare module 'fbjs/lib/everyObject' { + declare module.exports: {| + ( + object: mixed, + callback: (value: any, name: string, object: mixed) => any, + context?: any, + ): boolean, + |}; +} + +declare module 'fbjs/lib/everySet' { + declare module.exports: {| + ( + object: ?Set, + callback: (value: any, name: string, object: Set) => any, + context?: any, + ): boolean, + |}; +} + +declare module 'fbjs/lib/filterObject' { + declare module.exports: any; +} + +declare module 'fbjs/lib/forEachObject' { + declare module.exports: any; +} + +declare module 'fbjs/lib/groupArray' { + declare module.exports: any; +} + +declare module 'fbjs/lib/joinClasses' { + declare module.exports: {| + (className: mixed): string, + |}; +} + +declare module 'fbjs/lib/keyMirrorRecursive' { + declare module.exports: any; +} + +declare module 'fbjs/lib/keyOf' { + declare module.exports: any; +} + +declare module 'fbjs/lib/maxBy' { + declare module.exports: {| + ( + as: Iterable, + f: (a: A) => B, + compare?: ?(u: B, v: B) => number, + ): ?A, + |}; +} + +declare module 'fbjs/lib/memoizeStringOnly' { + declare module.exports: {| + (callback: (s: string) => T): (s: string) => T, + |}; +} + +declare module 'fbjs/lib/minBy' { + declare module.exports: {| + ( + as: Iterable, + f: (a: A) => B, + compare?: ?(u: B, v: B) => number, + ): ?A, + |}; +} + +declare module 'fbjs/lib/partitionArray' { + declare module.exports: {| + ( + array: Array, + predicate: (value: Tv, index: number, array: Array) => boolean, + context?: any, + ): [Array, Array], + |}; +} + +declare module 'fbjs/lib/partitionObject' { + declare module.exports: {| + ( + object: {[key: string]: Tv, ...}, + callback: ( + value: Tv, + key: string, + object: {[key: string]: Tv, ...}, + ) => boolean, + context?: any, + ): [{[key: string]: Tv, ...}, {[key: string]: Tv, ...}], + |}; +} + +declare module 'fbjs/lib/partitionObjectByKey' { + declare module.exports: any; +} + +declare module 'fbjs/lib/performance' { + declare module.exports: any; +} + +declare module 'fbjs/lib/performanceNow' { + declare module.exports: any; +} + +declare module 'fbjs/lib/requestAnimationFrame' { + declare module.exports: any; +} + +declare module 'fbjs/lib/someObject' { + declare module.exports: {| + ( + object: mixed, + callback: (value: any, name: string, object: mixed) => any, + context?: any, + ): boolean, + |}; +} + +declare module 'fbjs/lib/someSet' { + declare module.exports: {| + ( + set: Set, + callback: (value: T, key: T, set: Set) => boolean, + context?: any, + ): boolean, + |}; +} + +declare module 'fbjs/lib/keyMirror' { + declare module.exports: {| + (obj: T): $ObjMapi(K) => K>, + |}; +} + +declare module 'fbjs/lib/invariant' { + declare module.exports: {| + (condition: mixed, format: string, ...args: Array): void, + |}; +} diff --git a/flow/use-subscription.js b/flow/use-subscription.js new file mode 100644 index 00000000000..4b555c3b60e --- /dev/null +++ b/flow/use-subscription.js @@ -0,0 +1,19 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @flow strict + * @format + * @nolint + */ + +'use strict'; + +declare module 'use-subscription' { + declare export function useSubscription(subscription: {| + getCurrentValue: () => Value, + subscribe: (callback: Function) => () => void, + |}): Value; +}