react-navigation: Updated withNavigation HOC for suppressing prop requirement (#29208)

## Why?

Typescript requires assign of `navigation` on Component that is created with `withNavigation` HOC. But it comes with that function so it shouldn't require that property.

## Example

```typescript
//
// on the current version, this will give an error.
// with this PR, it will work.
//
interface IHelloProps extends Partial<NavigationInjectedProps> {
  hello: boolean;
}

const HelloBox: SFC<IHelloProps> = ({ navigation, hello }) => (
<View>
<TouchableHighlightCustom onPress={() => navigation.navigate('TEST', { hello })}>
        <Text>Hello</Text>
      </TouchableHighlightCustom>
</View>;
);

export default withNavigation(HelloBox);
```
----

Please fill in this template.

- [X] Use a meaningful title for the pull request. Include the name of the package modified.
- [X] Test the change in your own code. (Compile and run.)
- [x] Add or edit tests to reflect the change. (Run with `npm test`.)
- [x] Follow the advice from the [readme](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/README.md#make-a-pull-request).
- [X] Avoid [common mistakes](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/README.md#common-mistakes).
- [X] Run `npm run lint package-name` (or `tsc` if no `tslint.json` is present).

Select one of these and delete the others:

If adding a new definition:
- [ ] The package does not already provide its own types, or cannot have its `.d.ts` files generated via `--declaration`
- [ ] If this is for an NPM package, match the name. If not, do not conflict with the name of an NPM package.
- [ ] Create it with `dts-gen --dt`, not by basing it on an existing project.
- [ ] `tslint.json` should be present, and `tsconfig.json` should have `noImplicitAny`, `noImplicitThis`, `strictNullChecks`, and `strictFunctionTypes` set to `true`.

If changing an existing definition:
- [ ] Provide a URL to documentation or source code which provides context for the suggested changes: <<url here>>
- [ ] Increase the version number in the header if appropriate.
- [ ] If you are making substantial changes, consider adding a `tslint.json` containing `{ "extends": "dtslint/dt.json" }`.

If removing a declaration:
- [ ] If a package was never on DefinitelyTyped, you don't need to do anything. (If you wrote a package and provided types, you don't need to register it with us.)
- [ ] Delete the package's directory.
- [ ] Add it to `notNeededPackages.json`.
This commit is contained in:
Ilker Güller
2018-10-06 00:01:34 +02:00
committed by Wesley Wigham
parent dda6e33a6c
commit 4464cbbfe7

View File

@@ -1254,7 +1254,7 @@ export function withNavigation<T extends React.ComponentType<NavigationInjectedP
// For backwards compatibility
export function withNavigation<T = {}, P = NavigationParams>(
Component: React.ComponentType<T & NavigationInjectedProps<P>>,
Component: React.ComponentType<T | (T & NavigationInjectedProps<P>)>,
): React.ComponentType<T & { onRef?: React.Ref<React.Component<T & NavigationInjectedProps<P>>> }>;
export interface NavigationFocusInjectedProps<P = NavigationParams> extends NavigationInjectedProps<P> {