diff --git a/packages/core/src/getStateFromPath.tsx b/packages/core/src/getStateFromPath.tsx index e1e57831..c3d6cf51 100644 --- a/packages/core/src/getStateFromPath.tsx +++ b/packages/core/src/getStateFromPath.tsx @@ -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 }; } diff --git a/packages/core/src/types.tsx b/packages/core/src/types.tsx index c8f39682..dac13087 100644 --- a/packages/core/src/types.tsx +++ b/packages/core/src/types.tsx @@ -62,7 +62,9 @@ export type EventArg< preventDefault(): void; } : {}) & - (undefined extends Data ? { readonly data?: Data } : { readonly data: Data }); + (undefined extends Data + ? { readonly data?: Readonly } + : { readonly data: Readonly }); export type EventListenerCallback< EventMap extends EventMapBase, @@ -277,18 +279,18 @@ export type RouteProp< RouteName extends keyof ParamList > = Omit>, 'params'> & (undefined extends ParamList[RouteName] - ? { + ? Readonly<{ /** * Params for this route */ - params?: ParamList[RouteName]; - } - : { + params?: Readonly; + }> + : Readonly<{ /** * Params for this route */ - params: ParamList[RouteName]; - }); + params: Readonly; + }>); export type CompositeNavigationProp< A extends NavigationProp, diff --git a/packages/routers/src/types.tsx b/packages/routers/src/types.tsx index 390aa641..81312da3 100644 --- a/packages/routers/src/types.tsx +++ b/packages/routers/src/types.tsx @@ -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 -> & { - routes: (Omit, 'key'> & { state?: InitialState })[]; -}; +export type InitialState = Readonly< + Partial> & { + routes: (Omit, 'key'> & { state?: InitialState })[]; + } +>; export type PartialState = Partial< Omit -> & { - stale?: true; - type?: string; - routes: (Omit, 'key'> & { - key?: string; - state?: InitialState; - })[]; -}; +> & + Readonly<{ + stale?: true; + type?: string; + routes: (Omit, 'key'> & { + key?: string; + state?: InitialState; + })[]; + }>; -export type Route = { +export type Route = Readonly<{ /** * Unique key for the route. */ @@ -67,11 +68,11 @@ export type Route = { * Params for the route. */ params?: object; -}; +}>; export type ParamListBase = Record; -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 = { [key: string]: (...args: any) => Action;