Can't use extended StateDeclaration as a generic to StateObject
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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