Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# These are purely type definitions, no runtime code. Most of them
# are third-party code, too, so naturally don't match our style.
**/flow-typed/**
types/@react-navigation

# These are type-tests, made up of code that gets type-checked but
# never actually run. They're naturally full of dead code which
Expand Down
2 changes: 1 addition & 1 deletion .flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ module.name_mapper='^react-native/\(.*\)$' -> '<PROJECT_ROOT>/node_modules/react
module.name_mapper='^@?[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> '<PROJECT_ROOT>/node_modules/react-native/Libraries/Image/RelativeImageStub'
# This lets us write .js.flow files instead of libdefs.
# Add more libraries as needed to this pattern with `\|`: `foo\|bar\|…`.
module.name_mapper='^\(sqlite3\)$' -> '<PROJECT_ROOT>/types/\0'
module.name_mapper='^\(sqlite3\|@react-navigation/bottom-tabs\)$' -> '<PROJECT_ROOT>/types/\0'

suppress_type=$FlowIssue
suppress_type=$FlowFixMe
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ flow-typed/@react-navigation
# These are purely type definitions, no runtime code. Most of them
# are third-party code, too, so naturally don't match our style.
**/flow-typed/**
types/@react-navigation

# Third-party code: react-native. We leave this code in the style we
# received it in.
Expand Down
36 changes: 36 additions & 0 deletions __libdef-tests__/drawer_v5.x.x-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* @flow strict-local */
import { type NavigationProp } from '@react-navigation/drawer';

/* eslint-disable no-unused-vars */

function test_setParams() {
type NavProp<P> = NavigationProp<{| r: P |}, 'r'>;

function test_happy(navigation: NavProp<{| a: number |}>) {
navigation.setParams({ a: 1 });
}

function test_accepts_missing(navigation: NavProp<{| a: number, b: number |}>) {
navigation.setParams({ a: 1 });
}

function test_rejects_extra(navigation: NavProp<{| a: number |}>) {
// $FlowExpectedError[prop-missing]
navigation.setParams({ b: 1 });
}

function test_rejects_mismatch(navigation: NavProp<{| a: number |}>) {
// $FlowExpectedError[incompatible-call]
navigation.setParams({ a: 'a' });
}

function test_rejects_object_to_void(navigation: NavProp<void>) {
// $FlowExpectedError[incompatible-call]
navigation.setParams({ a: 1 });
}

function test_rejects_void_to_object(navigation: NavProp<{| a: number |}>) {
// $FlowExpectedError[incompatible-call]
navigation.setParams();
}
}
36 changes: 36 additions & 0 deletions __libdef-tests__/material-top-tabs_v5.x.x-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* @flow strict-local */
import { type NavigationProp } from '@react-navigation/material-top-tabs';

/* eslint-disable no-unused-vars */

function test_setParams() {
type NavProp<P> = NavigationProp<{| r: P |}, 'r'>;

function test_happy(navigation: NavProp<{| a: number |}>) {
navigation.setParams({ a: 1 });
}

function test_accepts_missing(navigation: NavProp<{| a: number, b: number |}>) {
navigation.setParams({ a: 1 });
}

function test_rejects_extra(navigation: NavProp<{| a: number |}>) {
// $FlowExpectedError[prop-missing]
navigation.setParams({ b: 1 });
}

function test_rejects_mismatch(navigation: NavProp<{| a: number |}>) {
// $FlowExpectedError[incompatible-call]
navigation.setParams({ a: 'a' });
}

function test_rejects_object_to_void(navigation: NavProp<void>) {
// $FlowExpectedError[incompatible-call]
navigation.setParams({ a: 1 });
}

function test_rejects_void_to_object(navigation: NavProp<{| a: number |}>) {
// $FlowExpectedError[incompatible-call]
navigation.setParams();
}
}
36 changes: 36 additions & 0 deletions __libdef-tests__/native_v5.x.x-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* @flow strict-local */
import { type NavigationProp } from '@react-navigation/native';

/* eslint-disable no-unused-vars */

function test_setParams() {
type NavProp<P> = NavigationProp<{| r: P |}, 'r'>;

function test_happy(navigation: NavProp<{| a: number |}>) {
navigation.setParams({ a: 1 });
}

function test_accepts_missing(navigation: NavProp<{| a: number, b: number |}>) {
navigation.setParams({ a: 1 });
}

function test_rejects_extra(navigation: NavProp<{| a: number |}>) {
// $FlowExpectedError[prop-missing]
navigation.setParams({ b: 1 });
}

function test_rejects_mismatch(navigation: NavProp<{| a: number |}>) {
// $FlowExpectedError[incompatible-call]
navigation.setParams({ a: 'a' });
}

function test_rejects_object_to_void(navigation: NavProp<void>) {
// $FlowExpectedError[incompatible-call]
navigation.setParams({ a: 1 });
}

function test_rejects_void_to_object(navigation: NavProp<{| a: number |}>) {
// $FlowExpectedError[incompatible-call]
navigation.setParams();
}
}
Loading