mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-05-25 20:21:46 +08:00
fix: mark some types as read-only
This commit is contained in:
@@ -260,6 +260,7 @@ export default function getStateFromPath(
|
||||
);
|
||||
|
||||
if (params) {
|
||||
// @ts-expect-error: params should be treated as read-only, but we're creating the state here so it doesn't matter
|
||||
route.params = { ...route.params, ...params };
|
||||
}
|
||||
|
||||
|
||||
@@ -62,7 +62,9 @@ export type EventArg<
|
||||
preventDefault(): void;
|
||||
}
|
||||
: {}) &
|
||||
(undefined extends Data ? { readonly data?: Data } : { readonly data: Data });
|
||||
(undefined extends Data
|
||||
? { readonly data?: Readonly<Data> }
|
||||
: { readonly data: Readonly<Data> });
|
||||
|
||||
export type EventListenerCallback<
|
||||
EventMap extends EventMapBase,
|
||||
@@ -277,18 +279,18 @@ export type RouteProp<
|
||||
RouteName extends keyof ParamList
|
||||
> = Omit<Route<Extract<RouteName, string>>, 'params'> &
|
||||
(undefined extends ParamList[RouteName]
|
||||
? {
|
||||
? Readonly<{
|
||||
/**
|
||||
* Params for this route
|
||||
*/
|
||||
params?: ParamList[RouteName];
|
||||
}
|
||||
: {
|
||||
params?: Readonly<ParamList[RouteName]>;
|
||||
}>
|
||||
: Readonly<{
|
||||
/**
|
||||
* Params for this route
|
||||
*/
|
||||
params: ParamList[RouteName];
|
||||
});
|
||||
params: Readonly<ParamList[RouteName]>;
|
||||
}>);
|
||||
|
||||
export type CompositeNavigationProp<
|
||||
A extends NavigationProp<ParamListBase, string, any, any>,
|
||||
|
||||
@@ -2,7 +2,7 @@ import type * as CommonActions from './CommonActions';
|
||||
|
||||
export type CommonNavigationAction = CommonActions.Action;
|
||||
|
||||
export type NavigationState = {
|
||||
export type NavigationState = Readonly<{
|
||||
/**
|
||||
* Unique key for the navigation state.
|
||||
*/
|
||||
@@ -35,26 +35,27 @@ export type NavigationState = {
|
||||
* Whether the navigation state has been rehydrated.
|
||||
*/
|
||||
stale: false;
|
||||
};
|
||||
}>;
|
||||
|
||||
export type InitialState = Partial<
|
||||
Omit<NavigationState, 'stale' | 'routes'>
|
||||
> & {
|
||||
routes: (Omit<Route<string>, 'key'> & { state?: InitialState })[];
|
||||
};
|
||||
export type InitialState = Readonly<
|
||||
Partial<Omit<NavigationState, 'stale' | 'routes'>> & {
|
||||
routes: (Omit<Route<string>, 'key'> & { state?: InitialState })[];
|
||||
}
|
||||
>;
|
||||
|
||||
export type PartialState<State extends NavigationState> = Partial<
|
||||
Omit<State, 'stale' | 'type' | 'key' | 'routes' | 'routeNames'>
|
||||
> & {
|
||||
stale?: true;
|
||||
type?: string;
|
||||
routes: (Omit<Route<string>, 'key'> & {
|
||||
key?: string;
|
||||
state?: InitialState;
|
||||
})[];
|
||||
};
|
||||
> &
|
||||
Readonly<{
|
||||
stale?: true;
|
||||
type?: string;
|
||||
routes: (Omit<Route<string>, 'key'> & {
|
||||
key?: string;
|
||||
state?: InitialState;
|
||||
})[];
|
||||
}>;
|
||||
|
||||
export type Route<RouteName extends string> = {
|
||||
export type Route<RouteName extends string> = Readonly<{
|
||||
/**
|
||||
* Unique key for the route.
|
||||
*/
|
||||
@@ -67,11 +68,11 @@ export type Route<RouteName extends string> = {
|
||||
* Params for the route.
|
||||
*/
|
||||
params?: object;
|
||||
};
|
||||
}>;
|
||||
|
||||
export type ParamListBase = Record<string, object | undefined>;
|
||||
|
||||
export type NavigationAction = {
|
||||
export type NavigationAction = Readonly<{
|
||||
/**
|
||||
* Type of the action (e.g. `NAVIGATE`)
|
||||
*/
|
||||
@@ -88,7 +89,7 @@ export type NavigationAction = {
|
||||
* Key of the navigator which should handle this action.
|
||||
*/
|
||||
target?: string;
|
||||
};
|
||||
}>;
|
||||
|
||||
export type ActionCreators<Action extends NavigationAction> = {
|
||||
[key: string]: (...args: any) => Action;
|
||||
|
||||
Reference in New Issue
Block a user