Skip to content

Commit

Permalink
Add missing class annotations xplat/js
Browse files Browse the repository at this point in the history
Reviewed By: SamChou19815

Differential Revision: D38373443

fbshipit-source-id: 1222c4845ebd6b72bd6f54af1a27cf8542dd883a
  • Loading branch information
pieterv authored and facebook-github-bot committed Aug 3, 2022
1 parent 2fa04be commit ee3d3c2
Show file tree
Hide file tree
Showing 66 changed files with 378 additions and 294 deletions.
2 changes: 1 addition & 1 deletion IntegrationTests/AccessibilityManagerTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import * as React from 'react';
const {TestModule} = NativeModules;

class AccessibilityManagerTest extends React.Component<{...}> {
componentDidMount() {
componentDidMount(): void {
invariant(
NativeAccessibilityManager,
"NativeAccessibilityManager doesn't exist",
Expand Down
2 changes: 1 addition & 1 deletion IntegrationTests/GlobalEvalWithSourceUrlTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const {View} = ReactNative;
const {TestModule} = ReactNative.NativeModules;

class GlobalEvalWithSourceUrlTest extends React.Component<{...}> {
componentDidMount() {
componentDidMount(): void {
if (typeof global.globalEvalWithSourceUrl !== 'function') {
throw new Error(
'Expected to find globalEvalWithSourceUrl function on global object but found ' +
Expand Down
2 changes: 1 addition & 1 deletion IntegrationTests/ImageSnapshotTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const {Image} = ReactNative;
const {TestModule} = ReactNative.NativeModules;

class ImageSnapshotTest extends React.Component<{...}> {
componentDidMount() {
componentDidMount(): void {
if (!TestModule.verifySnapshot) {
throw new Error('TestModule.verifySnapshot not defined.');
}
Expand Down
4 changes: 2 additions & 2 deletions IntegrationTests/IntegrationTestsApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ require('./LoggingTestModule');
type Test = any;

class IntegrationTestsApp extends React.Component<{...}, $FlowFixMeState> {
state = {
state: {test: ?Test} = {
test: (null: ?Test),
};

render() {
render(): React.Node {
if (this.state.test) {
return (
<ScrollView>
Expand Down
2 changes: 1 addition & 1 deletion IntegrationTests/SimpleSnapshotTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const {StyleSheet, View} = ReactNative;
const {TestModule} = ReactNative.NativeModules;

class SimpleSnapshotTest extends React.Component<{...}> {
componentDidMount() {
componentDidMount(): void {
if (!TestModule.verifySnapshot) {
throw new Error('TestModule.verifySnapshot not defined.');
}
Expand Down
2 changes: 1 addition & 1 deletion IntegrationTests/SyncMethodTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const {View} = ReactNative;
const {TestModule, RNTesterTestModule} = ReactNative.NativeModules;

class SyncMethodTest extends React.Component<{...}> {
componentDidMount() {
componentDidMount(): void {
if (
RNTesterTestModule.echoString('test string value') !== 'test string value'
) {
Expand Down
2 changes: 1 addition & 1 deletion IntegrationTests/TimersTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ class TimersTest extends React.Component<Props, State> {
);
}

_incrementInterval() {
_incrementInterval(): void {
if (this.state.count > 3) {
throw new Error('interval incremented past end.');
}
Expand Down
6 changes: 3 additions & 3 deletions IntegrationTests/WebSocketTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ class WebSocketTest extends React.Component<{...}, State> {
});
};

_socketIsConnected = () => {
_socketIsConnected = (): boolean => {
return this.state.socketState === 1; //'OPEN'
};

_socketIsDisconnected = () => {
_socketIsDisconnected = (): boolean => {
return this.state.socketState === 3; //'CLOSED'
};

Expand Down Expand Up @@ -106,7 +106,7 @@ class WebSocketTest extends React.Component<{...}, State> {
this._sendText(this.state.testMessage);
};

_receivedTestExpectedResponse = () => {
_receivedTestExpectedResponse = (): boolean => {
return this.state.lastMessage === this.state.testExpectedResponse;
};

Expand Down
4 changes: 2 additions & 2 deletions Libraries/Animated/AnimatedEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
Expand All @@ -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.',
Expand Down
6 changes: 3 additions & 3 deletions Libraries/Animated/createAnimatedComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -192,15 +192,15 @@ 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;
this._component = ref;
},
});

render() {
render(): React.Node {
const animatedProps =
this._propsAnimated.__getValue(this._initialAnimatedProps) || {};
const {style = {}, ...props} = animatedProps;
Expand Down
2 changes: 1 addition & 1 deletion Libraries/Animated/nodes/AnimatedNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down
7 changes: 5 additions & 2 deletions Libraries/Animated/nodes/AnimatedStyle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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];
Expand Down
4 changes: 2 additions & 2 deletions Libraries/BatchedBridge/MessageQueue.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand Down
6 changes: 3 additions & 3 deletions Libraries/Blob/FileReader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
17 changes: 9 additions & 8 deletions Libraries/Blob/URL.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,43 +54,44 @@ 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') {
Object.keys(params).forEach(key => this.append(key, params[key]));
}
}

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]();
}
Expand Down
6 changes: 3 additions & 3 deletions Libraries/Components/ScrollView/ScrollView.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions Libraries/Components/StatusBar/StatusBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Libraries/Inspector/BoxInspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}>
Expand Down
2 changes: 1 addition & 1 deletion Libraries/Inspector/InspectorPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
Expand Down
8 changes: 6 additions & 2 deletions Libraries/Inspector/NetworkOverlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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') {
Expand Down
2 changes: 1 addition & 1 deletion Libraries/Linking/Linking.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion Libraries/Lists/CellRenderMask.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down
8 changes: 4 additions & 4 deletions Libraries/Lists/FillRateHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading

0 comments on commit ee3d3c2

Please sign in to comment.