mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Add missing class annotations xplat/js
Reviewed By: SamChou19815 Differential Revision: D38373443 fbshipit-source-id: 1222c4845ebd6b72bd6f54af1a27cf8542dd883a
This commit is contained in:
committed by
Facebook GitHub Bot
parent
2fa04be062
commit
ee3d3c248d
@@ -177,7 +177,7 @@ class AnimatedEvent {
|
||||
this._listeners = this._listeners.filter(listener => listener !== callback);
|
||||
}
|
||||
|
||||
__attach(viewRef: any, eventName: string) {
|
||||
__attach(viewRef: any, eventName: string): void {
|
||||
invariant(
|
||||
this.__isNative,
|
||||
'Only native driven events need to be attached.',
|
||||
@@ -191,7 +191,7 @@ class AnimatedEvent {
|
||||
);
|
||||
}
|
||||
|
||||
__detach(viewTag: any, eventName: string) {
|
||||
__detach(viewTag: any, eventName: string): void {
|
||||
invariant(
|
||||
this.__isNative,
|
||||
'Only native driven events need to be detached.',
|
||||
|
||||
@@ -140,7 +140,7 @@ function createAnimatedComponent<Props: {+[string]: mixed, ...}, Instance>(
|
||||
// components. If you want to animate a composite component, you need to
|
||||
// re-render it. In this case, we have a fallback that uses forceUpdate.
|
||||
// This fallback is also called in Fabric.
|
||||
_animatedPropsCallback = () => {
|
||||
_animatedPropsCallback = (): void => {
|
||||
if (this._component == null) {
|
||||
// AnimatedProps is created in will-mount because it's used in render.
|
||||
// But this callback may be invoked before mount in async mode,
|
||||
@@ -192,7 +192,7 @@ function createAnimatedComponent<Props: {+[string]: mixed, ...}, Instance>(
|
||||
}
|
||||
}
|
||||
|
||||
_setComponentRef = setAndForwardRef({
|
||||
_setComponentRef: (ref: React.ElementRef<any>) => void = setAndForwardRef({
|
||||
getForwardedRef: () => this.props.forwardedRef,
|
||||
setLocalRef: ref => {
|
||||
this._prevComponent = this._component;
|
||||
@@ -200,7 +200,7 @@ function createAnimatedComponent<Props: {+[string]: mixed, ...}, Instance>(
|
||||
},
|
||||
});
|
||||
|
||||
render() {
|
||||
render(): React.Node {
|
||||
const animatedProps =
|
||||
this._propsAnimated.__getValue(this._initialAnimatedProps) || {};
|
||||
const {style = {}, ...props} = animatedProps;
|
||||
|
||||
@@ -53,7 +53,7 @@ class AnimatedNode {
|
||||
this._listeners = {};
|
||||
}
|
||||
|
||||
__makeNative(platformConfig: ?PlatformConfig) {
|
||||
__makeNative(platformConfig: ?PlatformConfig): void {
|
||||
if (!this.__isNative) {
|
||||
throw new Error('This node cannot be made a "native" animated node');
|
||||
}
|
||||
|
||||
@@ -34,7 +34,10 @@ class AnimatedStyle extends AnimatedWithChildren {
|
||||
}
|
||||
|
||||
// Recursively get values for nested styles (like iOS's shadowOffset)
|
||||
_walkStyleAndGetValues(style: any, initialStyle: ?Object) {
|
||||
_walkStyleAndGetValues(
|
||||
style: any,
|
||||
initialStyle: ?Object,
|
||||
): {[string]: any | {...}} {
|
||||
const updatedStyle: {[string]: any | {...}} = {};
|
||||
for (const key in style) {
|
||||
const value = style[key];
|
||||
@@ -63,7 +66,7 @@ class AnimatedStyle extends AnimatedWithChildren {
|
||||
}
|
||||
|
||||
// Recursively get animated values for nested styles (like iOS's shadowOffset)
|
||||
_walkStyleAndGetAnimatedValues(style: any) {
|
||||
_walkStyleAndGetAnimatedValues(style: any): {[string]: any | {...}} {
|
||||
const updatedStyle: {[string]: any | {...}} = {};
|
||||
for (const key in style) {
|
||||
const value = style[key];
|
||||
|
||||
@@ -241,7 +241,7 @@ class MessageQueue {
|
||||
params: mixed[],
|
||||
onFail: ?(...mixed[]) => void,
|
||||
onSucc: ?(...mixed[]) => void,
|
||||
) {
|
||||
): void {
|
||||
this.processCallbacks(moduleID, methodID, params, onFail, onSucc);
|
||||
|
||||
this._queue[MODULE_IDS].push(moduleID);
|
||||
@@ -427,7 +427,7 @@ class MessageQueue {
|
||||
Systrace.endEvent();
|
||||
}
|
||||
|
||||
__invokeCallback(cbID: number, args: mixed[]) {
|
||||
__invokeCallback(cbID: number, args: mixed[]): void {
|
||||
this._lastFlush = Date.now();
|
||||
this._eventLoopStartTime = this._lastFlush;
|
||||
|
||||
|
||||
@@ -73,11 +73,11 @@ class FileReader extends (EventTarget(...READER_EVENTS): any) {
|
||||
}
|
||||
}
|
||||
|
||||
readAsArrayBuffer() {
|
||||
readAsArrayBuffer(): any {
|
||||
throw new Error('FileReader.readAsArrayBuffer is not implemented');
|
||||
}
|
||||
|
||||
readAsDataURL(blob: ?Blob) {
|
||||
readAsDataURL(blob: ?Blob): void {
|
||||
this._aborted = false;
|
||||
|
||||
if (blob == null) {
|
||||
@@ -104,7 +104,7 @@ class FileReader extends (EventTarget(...READER_EVENTS): any) {
|
||||
);
|
||||
}
|
||||
|
||||
readAsText(blob: ?Blob, encoding: string = 'UTF-8') {
|
||||
readAsText(blob: ?Blob, encoding: string = 'UTF-8'): void {
|
||||
this._aborted = false;
|
||||
|
||||
if (blob == null) {
|
||||
|
||||
@@ -54,7 +54,7 @@ if (
|
||||
// Small subset from whatwg-url: https://github.com/jsdom/whatwg-url/tree/master/src
|
||||
// The reference code bloat comes from Unicode issues with URLs, so those won't work here.
|
||||
export class URLSearchParams {
|
||||
_searchParams = [];
|
||||
_searchParams: Array<Array<string>> = [];
|
||||
|
||||
constructor(params: any) {
|
||||
if (typeof params === 'object') {
|
||||
@@ -62,35 +62,36 @@ export class URLSearchParams {
|
||||
}
|
||||
}
|
||||
|
||||
append(key: string, value: string) {
|
||||
append(key: string, value: string): void {
|
||||
this._searchParams.push([key, value]);
|
||||
}
|
||||
|
||||
delete(name: string) {
|
||||
delete(name: string): void {
|
||||
throw new Error('URLSearchParams.delete is not implemented');
|
||||
}
|
||||
|
||||
get(name: string) {
|
||||
get(name: string): void {
|
||||
throw new Error('URLSearchParams.get is not implemented');
|
||||
}
|
||||
|
||||
getAll(name: string) {
|
||||
getAll(name: string): void {
|
||||
throw new Error('URLSearchParams.getAll is not implemented');
|
||||
}
|
||||
|
||||
has(name: string) {
|
||||
has(name: string): void {
|
||||
throw new Error('URLSearchParams.has is not implemented');
|
||||
}
|
||||
|
||||
set(name: string, value: string) {
|
||||
set(name: string, value: string): void {
|
||||
throw new Error('URLSearchParams.set is not implemented');
|
||||
}
|
||||
|
||||
sort() {
|
||||
sort(): void {
|
||||
throw new Error('URLSearchParams.sort is not implemented');
|
||||
}
|
||||
|
||||
// $FlowFixMe[unsupported-syntax]
|
||||
// $FlowFixMe[missing-local-annot]
|
||||
[Symbol.iterator]() {
|
||||
return this._searchParams[Symbol.iterator]();
|
||||
}
|
||||
|
||||
@@ -825,7 +825,7 @@ class ScrollView extends React.Component<Props, State> {
|
||||
}
|
||||
}
|
||||
|
||||
_setNativeRef = setAndForwardRef({
|
||||
_setNativeRef: $FlowFixMe = setAndForwardRef({
|
||||
getForwardedRef: () => this.props.scrollViewRef,
|
||||
setLocalRef: ref => {
|
||||
this._scrollViewRef = ref;
|
||||
@@ -1107,7 +1107,7 @@ class ScrollView extends React.Component<Props, State> {
|
||||
}
|
||||
};
|
||||
|
||||
_getKeyForIndex(index: $FlowFixMe, childArray: $FlowFixMe) {
|
||||
_getKeyForIndex(index: $FlowFixMe, childArray: $FlowFixMe): $FlowFixMe {
|
||||
const child = childArray[index];
|
||||
return child && child.key;
|
||||
}
|
||||
@@ -1204,7 +1204,7 @@ class ScrollView extends React.Component<Props, State> {
|
||||
_scrollViewRef: ?React.ElementRef<HostComponent<mixed>> = null;
|
||||
|
||||
_innerViewRef: ?React.ElementRef<typeof View> = null;
|
||||
_setInnerViewRef = setAndForwardRef({
|
||||
_setInnerViewRef: $FlowFixMe = setAndForwardRef({
|
||||
getForwardedRef: () => this.props.innerViewRef,
|
||||
setLocalRef: ref => {
|
||||
this._innerViewRef = ref;
|
||||
|
||||
@@ -223,9 +223,9 @@ function createStackEntry(props: any): any {
|
||||
* `currentHeight` (Android only) The height of the status bar.
|
||||
*/
|
||||
class StatusBar extends React.Component<Props> {
|
||||
static _propsStack = [];
|
||||
static _propsStack: Array<any> = [];
|
||||
|
||||
static _defaultProps = createStackEntry({
|
||||
static _defaultProps: any = createStackEntry({
|
||||
backgroundColor:
|
||||
Platform.OS === 'android'
|
||||
? NativeStatusBarManagerAndroid.getConstants()
|
||||
@@ -309,7 +309,7 @@ class StatusBar extends React.Component<Props> {
|
||||
* @param color Background color.
|
||||
* @param animated Animate the style change.
|
||||
*/
|
||||
static setBackgroundColor(color: string, animated?: boolean) {
|
||||
static setBackgroundColor(color: string, animated?: boolean): void {
|
||||
if (Platform.OS !== 'android') {
|
||||
console.warn('`setBackgroundColor` is only available on Android');
|
||||
return;
|
||||
|
||||
@@ -49,7 +49,7 @@ class BoxInspector extends React.Component<$FlowFixMeProps> {
|
||||
}
|
||||
|
||||
class BoxContainer extends React.Component<$FlowFixMeProps> {
|
||||
render() {
|
||||
render(): React.Node {
|
||||
const box = this.props.box;
|
||||
return (
|
||||
<View style={styles.box}>
|
||||
|
||||
@@ -120,7 +120,7 @@ type InspectorPanelButtonProps = $ReadOnly<{|
|
||||
|}>;
|
||||
|
||||
class InspectorPanelButton extends React.Component<InspectorPanelButtonProps> {
|
||||
render() {
|
||||
render(): React.Node {
|
||||
return (
|
||||
<TouchableHighlight
|
||||
onPress={() => this.props.onClick(!this.props.pressed)}
|
||||
|
||||
@@ -95,7 +95,11 @@ class NetworkOverlay extends React.Component<Props, State> {
|
||||
// scroll to the bottom as new network requests come in, or if the user has
|
||||
// intentionally scrolled away from the bottom - to instead flash the scroll bar
|
||||
// and keep the current position
|
||||
_requestsListViewScrollMetrics = {
|
||||
_requestsListViewScrollMetrics: {
|
||||
contentLength: number,
|
||||
offset: number,
|
||||
visibleLength: number,
|
||||
} = {
|
||||
offset: 0,
|
||||
visibleLength: 0,
|
||||
contentLength: 0,
|
||||
@@ -363,7 +367,7 @@ class NetworkOverlay extends React.Component<Props, State> {
|
||||
);
|
||||
};
|
||||
|
||||
_renderItemDetail(id: number) {
|
||||
_renderItemDetail(id: number): React.Node {
|
||||
const requestItem = this.state.requests[id];
|
||||
const details = Object.keys(requestItem).map(key => {
|
||||
if (key === 'id') {
|
||||
|
||||
@@ -123,7 +123,7 @@ class Linking extends NativeEventEmitter<LinkingEventDefinitions> {
|
||||
}
|
||||
}
|
||||
|
||||
_validateURL(url: string) {
|
||||
_validateURL(url: string): void {
|
||||
invariant(
|
||||
typeof url === 'string',
|
||||
'Invalid URL: should be a string. Was: ' + url,
|
||||
|
||||
@@ -45,7 +45,7 @@ export class CellRenderMask {
|
||||
return this._regions;
|
||||
}
|
||||
|
||||
addCells(cells: {first: number, last: number}) {
|
||||
addCells(cells: {first: number, last: number}): void {
|
||||
invariant(
|
||||
cells.first >= 0 &&
|
||||
cells.first < this._numCells &&
|
||||
|
||||
@@ -49,12 +49,12 @@ let _sampleRate = DEBUG ? 1 : null;
|
||||
* `SceneTracker.getActiveScene` to determine the context of the events.
|
||||
*/
|
||||
class FillRateHelper {
|
||||
_anyBlankStartTime = (null: ?number);
|
||||
_anyBlankStartTime: ?number = null;
|
||||
_enabled = false;
|
||||
_getFrameMetrics: (index: number, props: FrameMetricProps) => ?FrameMetrics;
|
||||
_info = new Info();
|
||||
_mostlyBlankStartTime = (null: ?number);
|
||||
_samplesStartTime = (null: ?number);
|
||||
_info: Info = new Info();
|
||||
_mostlyBlankStartTime: ?number = null;
|
||||
_samplesStartTime: ?number = null;
|
||||
|
||||
static addListener(callback: FillRateInfo => void): {
|
||||
remove: () => void,
|
||||
|
||||
@@ -401,7 +401,7 @@ export function withSubscription(
|
||||
WrappedComponent: SubscribedComponent,
|
||||
): React.AbstractComponent<{||}> {
|
||||
class LogBoxStateSubscription extends React.Component<Props, State> {
|
||||
static getDerivedStateFromError() {
|
||||
static getDerivedStateFromError(): {hasError: boolean} {
|
||||
return {hasError: true};
|
||||
}
|
||||
|
||||
@@ -413,7 +413,7 @@ export function withSubscription(
|
||||
|
||||
_subscription: ?Subscription;
|
||||
|
||||
state = {
|
||||
state: State = {
|
||||
logs: new Set(),
|
||||
isDisabled: false,
|
||||
hasError: false,
|
||||
|
||||
@@ -118,7 +118,7 @@ class PushNotificationIOS {
|
||||
*
|
||||
* See https://reactnative.dev/docs/pushnotificationios#presentlocalnotification
|
||||
*/
|
||||
static presentLocalNotification(details: Object) {
|
||||
static presentLocalNotification(details: Object): void {
|
||||
invariant(
|
||||
NativePushNotificationManagerIOS,
|
||||
'PushNotificationManager is not available.',
|
||||
@@ -131,7 +131,7 @@ class PushNotificationIOS {
|
||||
*
|
||||
* See https://reactnative.dev/docs/pushnotificationios#schedulelocalnotification
|
||||
*/
|
||||
static scheduleLocalNotification(details: Object) {
|
||||
static scheduleLocalNotification(details: Object): void {
|
||||
invariant(
|
||||
NativePushNotificationManagerIOS,
|
||||
'PushNotificationManager is not available.',
|
||||
@@ -144,7 +144,7 @@ class PushNotificationIOS {
|
||||
*
|
||||
* See https://reactnative.dev/docs/pushnotificationios#cancelalllocalnotifications
|
||||
*/
|
||||
static cancelAllLocalNotifications() {
|
||||
static cancelAllLocalNotifications(): void {
|
||||
invariant(
|
||||
NativePushNotificationManagerIOS,
|
||||
'PushNotificationManager is not available.',
|
||||
@@ -198,7 +198,7 @@ class PushNotificationIOS {
|
||||
*
|
||||
* See https://reactnative.dev/docs/pushnotificationios#setapplicationiconbadgenumber
|
||||
*/
|
||||
static setApplicationIconBadgeNumber(number: number) {
|
||||
static setApplicationIconBadgeNumber(number: number): void {
|
||||
invariant(
|
||||
NativePushNotificationManagerIOS,
|
||||
'PushNotificationManager is not available.',
|
||||
@@ -211,7 +211,7 @@ class PushNotificationIOS {
|
||||
*
|
||||
* See https://reactnative.dev/docs/pushnotificationios#getapplicationiconbadgenumber
|
||||
*/
|
||||
static getApplicationIconBadgeNumber(callback: Function) {
|
||||
static getApplicationIconBadgeNumber(callback: Function): void {
|
||||
invariant(
|
||||
NativePushNotificationManagerIOS,
|
||||
'PushNotificationManager is not available.',
|
||||
@@ -224,7 +224,7 @@ class PushNotificationIOS {
|
||||
*
|
||||
* See https://reactnative.dev/docs/pushnotificationios#cancellocalnotification
|
||||
*/
|
||||
static cancelLocalNotifications(userInfo: Object) {
|
||||
static cancelLocalNotifications(userInfo: Object): void {
|
||||
invariant(
|
||||
NativePushNotificationManagerIOS,
|
||||
'PushNotificationManager is not available.',
|
||||
@@ -237,7 +237,7 @@ class PushNotificationIOS {
|
||||
*
|
||||
* See https://reactnative.dev/docs/pushnotificationios#getscheduledlocalnotifications
|
||||
*/
|
||||
static getScheduledLocalNotifications(callback: Function) {
|
||||
static getScheduledLocalNotifications(callback: Function): void {
|
||||
invariant(
|
||||
NativePushNotificationManagerIOS,
|
||||
'PushNotificationManager is not available.',
|
||||
@@ -251,7 +251,10 @@ class PushNotificationIOS {
|
||||
*
|
||||
* See https://reactnative.dev/docs/pushnotificationios#addeventlistener
|
||||
*/
|
||||
static addEventListener(type: PushNotificationEventName, handler: Function) {
|
||||
static addEventListener(
|
||||
type: PushNotificationEventName,
|
||||
handler: Function,
|
||||
): void {
|
||||
invariant(
|
||||
type === 'notification' ||
|
||||
type === 'register' ||
|
||||
@@ -301,7 +304,7 @@ class PushNotificationIOS {
|
||||
static removeEventListener(
|
||||
type: PushNotificationEventName,
|
||||
handler: Function,
|
||||
) {
|
||||
): void {
|
||||
invariant(
|
||||
type === 'notification' ||
|
||||
type === 'register' ||
|
||||
@@ -362,7 +365,7 @@ class PushNotificationIOS {
|
||||
*
|
||||
* See https://reactnative.dev/docs/pushnotificationios#abandonpermissions
|
||||
*/
|
||||
static abandonPermissions() {
|
||||
static abandonPermissions(): void {
|
||||
invariant(
|
||||
NativePushNotificationManagerIOS,
|
||||
'PushNotificationManager is not available.',
|
||||
@@ -376,7 +379,7 @@ class PushNotificationIOS {
|
||||
*
|
||||
* See https://reactnative.dev/docs/pushnotificationios#checkpermissions
|
||||
*/
|
||||
static checkPermissions(callback: Function) {
|
||||
static checkPermissions(callback: Function): void {
|
||||
invariant(typeof callback === 'function', 'Must provide a valid callback');
|
||||
invariant(
|
||||
NativePushNotificationManagerIOS,
|
||||
@@ -463,7 +466,7 @@ class PushNotificationIOS {
|
||||
*
|
||||
* See https://reactnative.dev/docs/pushnotificationios#finish
|
||||
*/
|
||||
finish(fetchResult: string) {
|
||||
finish(fetchResult: string): void {
|
||||
if (
|
||||
!this._isRemote ||
|
||||
!this._notificationId ||
|
||||
|
||||
@@ -21,12 +21,12 @@ describe('setAndForwardRef', () => {
|
||||
let outerFuncCalled: ?boolean = false;
|
||||
|
||||
class ForwardedComponent extends React.Component<{||}> {
|
||||
testFunc() {
|
||||
testFunc(): any {
|
||||
innerFuncCalled = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
render() {
|
||||
render(): any {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -38,7 +38,7 @@ describe('setAndForwardRef', () => {
|
||||
|
||||
class TestComponent extends React.Component<Props> {
|
||||
_nativeRef: ?React.ElementRef<typeof ForwardedComponent> = null;
|
||||
_setNativeRef = setAndForwardRef({
|
||||
_setNativeRef: (ref: React.ElementRef<any>) => void = setAndForwardRef({
|
||||
getForwardedRef: () => this.props.forwardedRef,
|
||||
setLocalRef: ref => {
|
||||
this._nativeRef = ref;
|
||||
@@ -51,7 +51,7 @@ describe('setAndForwardRef', () => {
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
render(): React.Node {
|
||||
return <ForwardedComponent ref={this._setNativeRef} />;
|
||||
}
|
||||
}
|
||||
@@ -111,7 +111,7 @@ describe('setAndForwardRef', () => {
|
||||
/* eslint-enable react/no-string-refs */
|
||||
}
|
||||
|
||||
render() {
|
||||
render(): React.Node {
|
||||
/**
|
||||
* Can't directly pass the test component to `ReactTestRenderer.create`,
|
||||
* otherwise it will throw. See:
|
||||
|
||||
@@ -40,7 +40,7 @@ class TestViewInstance {
|
||||
return testID == null ? null : new TestViewInstance(testID);
|
||||
}
|
||||
|
||||
static named(name: string) {
|
||||
static named(name: string): $FlowFixMe {
|
||||
// $FlowIssue[prop-missing] - Flow does not support type augmentation.
|
||||
return expect.testViewInstance(name);
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ class TestEffect {
|
||||
this.name = name;
|
||||
this.key = key;
|
||||
}
|
||||
static called(name: string, key: ?string) {
|
||||
static called(name: string, key: ?string): $FlowFixMe {
|
||||
// $FlowIssue[prop-missing] - Flow does not support type augmentation.
|
||||
return expect.effect(name, key);
|
||||
}
|
||||
@@ -61,7 +61,7 @@ class TestEffectCleanup {
|
||||
this.name = name;
|
||||
this.key = key;
|
||||
}
|
||||
static called(name: string, key: ?string) {
|
||||
static called(name: string, key: ?string): $FlowFixMe {
|
||||
// $FlowIssue[prop-missing] - Flow does not support type augmentation.
|
||||
return expect.effectCleanup(name, key);
|
||||
}
|
||||
|
||||
@@ -137,31 +137,31 @@ class PerformanceLogger implements IPerformanceLogger {
|
||||
this._closed = true;
|
||||
}
|
||||
|
||||
currentTimestamp() {
|
||||
currentTimestamp(): number {
|
||||
return getCurrentTimestamp();
|
||||
}
|
||||
|
||||
getExtras() {
|
||||
getExtras(): {[key: string]: ?ExtraValue} {
|
||||
return this._extras;
|
||||
}
|
||||
|
||||
getPoints() {
|
||||
getPoints(): {[key: string]: ?number} {
|
||||
return this._points;
|
||||
}
|
||||
|
||||
getPointExtras() {
|
||||
getPointExtras(): {[key: string]: ?Extras} {
|
||||
return this._pointExtras;
|
||||
}
|
||||
|
||||
getTimespans() {
|
||||
getTimespans(): {[key: string]: ?Timespan} {
|
||||
return this._timespans;
|
||||
}
|
||||
|
||||
hasTimespan(key: string) {
|
||||
hasTimespan(key: string): boolean {
|
||||
return !!this._timespans[key];
|
||||
}
|
||||
|
||||
isClosed() {
|
||||
isClosed(): boolean {
|
||||
return this._closed;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user