ui-router / ui-router/angular

Can't use extended StateDeclaration as a generic to StateObject

Open
#990 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
365
Forks
139
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the TypeScript definitions for StateObject, StateDeclaration, and HookMatchCriteria, then compare them with the RouteDefinition example in this issue. Determine whether StateObject can preserve an extended StateDeclaration type for hook callbacks; done should include a supported typing approach and coverage for the demonstrated cast scenario.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, typescript
Domain
frontend, web-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.