angular icon indicating copy to clipboard operation
angular copied to clipboard

Can't use extended StateDeclaration as a generic to StateObject

Open jpike88 opened this issue 1 year ago • 0 comments

Why are StateObject and StateDeclaration so decoupled? Wouldn't it make sense for StateObject to have StateDeclaration as a generic, so I can cast types properly?

example:


type RouteDefinition = Readonly<
	Ng2StateDeclaration & {
		menuContent?: {
			component: new (..._: any[]) => {};
		};
		data?: {
			title: string;
			presentationType?: string;
			tabs?: {
				label: string;
				value: string;
				component: new (..._: any[]) => {};
				data?: {
					title: string;
				};
				visible?: () => boolean;
				permissionsRequired?: PermissionKey[];
				params?: {
					[s: string]: any;
				};
			}[];
		};
		squash?: boolean;
		permissionKey?: PermissionKey;
		visible?: () => boolean;
		url?: string;
		resolve?: any;
		params?: { [s: string]: any };
	}
>;

The below errors because RouteDefinition isn't compatible with StateObject, which I understand... but that's where I get stuck.

const requiresPermissionCriteria: HookMatchCriteria = {
		to: (state: RouteDefinition) => {
			targetState = state.name;
			permissionKey = state.data?.permissionKey;
			return state.data?.permissionKey;
		},
	};

jpike88 avatar May 28 '24 03:05 jpike88