Skip to content

Can't use extended StateDeclaration as a generic to StateObject #990

Open
@jpike88

Description

@jpike88

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;
		},
	};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions