Skip to content

Commit

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

Differential Revision: D38086573

fbshipit-source-id: 498cee3593fd9430a41bca61747106c3c2550bc9
  • Loading branch information
pieterv authored and facebook-github-bot committed Jul 22, 2022
1 parent a8e3665 commit 404dd87
Show file tree
Hide file tree
Showing 18 changed files with 33 additions and 33 deletions.
2 changes: 1 addition & 1 deletion packages/react-relay/ReactRelayQueryFetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ class ReactRelayQueryFetcher {
}: {
notifyFirstResult: boolean,
...
}) {
}): void {
invariant(
this._fetchOptions,
'ReactRelayQueryFetcher: `_onQueryDataAvailable` should have been called after having called `fetch`',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class BarComponent extends React.Component<{
requiredProp: string,
...
}> {
static defaultProps = {
static defaultProps: {defaultProp: string} = {
defaultProp: 'default',
};
getNum(): number {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ class FooComponent extends React.Component {
requiredProp: string,
...
};
static defaultProps = {
static defaultProps: {defaultProp: string} = {
defaultProp: 'default',
};
getNum(): number {
return 42;
}
render() {
render(): React.Node {
const reqLen = this.props.requiredProp.length;
const optionalProp = this.props.optionalProp;

Expand Down Expand Up @@ -157,7 +157,7 @@ module.exports = {
/** $FlowExpectedError: Foo `getNum` gives number, but `getString` assumes string **/
return bad ? 'not good' : ok;
}
render() {
render(): React.Node {
return (
<Foo
componentRef={ref => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ class FooComponent extends React.Component {
requiredProp: string,
...
};
static defaultProps = {
static defaultProps: {defaultProp: string} = {
defaultProp: 'default',
};
getNum(): number {
return 42;
}
render() {
render(): React.Node {
const reqLen = this.props.requiredProp.length;
const optionalProp = this.props.optionalProp;

Expand Down Expand Up @@ -140,7 +140,7 @@ module.exports = {
/** $FlowExpectedError: Foo `getNum` gives number, but `getString` assumes string **/
return bad ? 'not good' : ok;
}
render() {
render(): React.Node {
return (
<Foo
componentRef={ref => {
Expand Down
4 changes: 2 additions & 2 deletions packages/react-relay/relay-hooks/FragmentResource.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class ClientEdgeQueryResultsCache {
}
}

_retain(id: string) {
_retain(id: string): {dispose: () => void} {
const retainCount = (this._retainCounts.get(id) ?? 0) + 1;
this._retainCounts.set(id, retainCount);
return {
Expand Down Expand Up @@ -479,7 +479,7 @@ class FragmentResourceImpl {
fragmentRef: mixed,
request: ConcreteRequest,
clientEdgeDestinationID: DataID,
) {
): {queryResult: QueryResult, requestDescriptor: RequestDescriptor} {
const originalVariables = getVariablesFromFragment(
fragmentNode,
fragmentRef,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ describe('useBlockingPaginationFragment', () => {
let Renderer;

class ErrorBoundary extends React.Component<any, any> {
state = {error: null};
state: any | {error: null} = {error: null};
componentDidCatch(error: Error) {
this.setState({error});
}
render() {
render(): any | React.Node {
const {children, fallback} = this.props;
const {error} = this.state;
if (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ describe('useBlockingPaginationFragment with useTransition', () => {
let Renderer;

class ErrorBoundary extends React.Component<any, any> {
state = {error: null};
state: any | {error: null} = {error: null};
componentDidCatch(error: Error) {
this.setState({error});
}
render() {
render(): any | React.Node {
const {children, fallback} = this.props;
const {error} = this.state;
if (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,12 @@ describe('useLazyLoadQueryNode', () => {
errorBoundaryDidCatchFn = jest.fn();

class ErrorBoundary extends React.Component<any, any> {
state = {error: null};
state: any | {error: null} = {error: null};
componentDidCatch(error: Error) {
errorBoundaryDidCatchFn(error);
this.setState({error});
}
render() {
render(): any | React.Node {
const {children, fallback} = this.props;
const {error} = this.state;
if (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,11 @@ describe.each([
let unsubscribe;

class ErrorBoundary extends React.Component<any, any> {
state = {error: null};
state: {error: ?Error} = {error: null};
componentDidCatch(error: Error) {
this.setState({error});
}
render() {
render(): React.Node {
const {children, fallback} = this.props;
const {error} = this.state;
if (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class ErrorBoundary extends React.Component<$FlowFixMe, $FlowFixMe> {
this.setState({error});
}

render() {
render(): any {
const {children, fallback} = this.props;
const {error} = this.state;
if (error != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,11 @@ describe.each([
let Renderer;

class ErrorBoundary extends React.Component<any, any> {
state = {error: null};
state: {error: ?Error} = {error: null};
componentDidCatch(error: Error) {
this.setState({error});
}
render() {
render(): React.Node {
const {children, fallback} = this.props;
const {error} = this.state;
if (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,12 @@ describe('useLazyLoadQuery_REACT_CACHE', () => {

let errorBoundaryDidCatchFn;
class ErrorBoundary extends React.Component<any, any> {
state = {error: null};
state: {error: ?Error} = {error: null};
componentDidCatch(error: Error) {
errorBoundaryDidCatchFn(error);
this.setState({error});
}
render() {
render(): React.Node {
const {children, fallback} = this.props;
const {error} = this.state;
if (error) {
Expand Down
2 changes: 1 addition & 1 deletion packages/relay-runtime/store/OperationExecutor.js
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ class Executor<TMutation: MutationParameters> {
_normalizeFollowupPayload(
followupPayload: FollowupPayload,
normalizationNode: NormalizationSelectableNode,
) {
): RelayResponsePayload {
let variables;
if (
normalizationNode.kind === 'SplitOperation' &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class GraphModeHandler {
this._populateRecord(record, chunk);
}

_populateRecord(parentRecord: Record, chunk: DataChunk) {
_populateRecord(parentRecord: Record, chunk: DataChunk): void {
for (const [key, value] of Object.entries(chunk)) {
switch (key) {
case '$streamID':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export class GraphModeNormalizer {
this.duplicateFieldsAvoided = 0;
}

_getStreamID() {
_getStreamID(): number {
return this._nextStreamID++;
}

Expand All @@ -195,7 +195,7 @@ export class GraphModeNormalizer {

// TODO: The GraphMode proposal outlines different approachs to derive keys. We
// can expriment with different approaches here.
_getStorageKey(selection: NormalizationField) {
_getStorageKey(selection: NormalizationField): string {
return getStorageKey(selection, this._variables);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class RelayOptimisticRecordSource implements MutableRecordSource {
return Object.keys(this.toJSON()).length;
}

toJSON() {
toJSON(): {[DataID]: ?Record} {
const merged = {...this._base.toJSON()};
this._sink.getRecordIDs().forEach(dataID => {
const record = this.get(dataID);
Expand Down
8 changes: 4 additions & 4 deletions packages/relay-runtime/store/RelayResponseNormalizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ class RelayResponseNormalizer {
moduleImport: NormalizationModuleImport,
record: Record,
data: PayloadData,
) {
): void {
invariant(
typeof data === 'object' && data,
'RelayResponseNormalizer: Expected data for @module to be an object.',
Expand Down Expand Up @@ -477,7 +477,7 @@ class RelayResponseNormalizer {
selection: NormalizationLinkedField | NormalizationScalarField,
record: Record,
data: PayloadData,
) {
): void {
invariant(
typeof data === 'object' && data,
'writeField(): Expected data for field `%s` to be an object.',
Expand Down Expand Up @@ -569,7 +569,7 @@ class RelayResponseNormalizer {
selection: NormalizationActorChange,
record: Record,
data: PayloadData,
) {
): void {
const field = selection.linkedField;
invariant(
typeof data === 'object' && data,
Expand Down Expand Up @@ -662,7 +662,7 @@ class RelayResponseNormalizer {
selection: NormalizationFlightField,
record: Record,
data: PayloadData,
) {
): void {
const responseKey = selection.alias || selection.name;
const storageKey = getStorageKey(selection, this._variables);
const fieldValue = data[responseKey];
Expand Down
2 changes: 1 addition & 1 deletion packages/relay-test-utils/RelayMockPayloadGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ class RelayMockPayloadGenerator {
value: mixed | Array<mixed>,
path: $ReadOnlyArray<string>,
applicationName: string,
) {
): ?(string | Array<string>) {
if (value === undefined) {
return value;
}
Expand Down

0 comments on commit 404dd87

Please sign in to comment.