-
-
Notifications
You must be signed in to change notification settings - Fork 152
Closed
Description
π© Feature Request
Is your feature request related to a problem?
I'm creating a navigation sidebar. It has dropdowns, with nested dropdowns inside of those (optionally).
Imagine this type of thing:
- Settings
- Account
- Notifications
- Security
- Password
- Account
Is there a way I can self-reference a MenuItem that has dropdownItems?: MenuItem with a maximum depth?
Describe the solution you'd like
Pseudocode (of how I imagine code should work):
type MenuItem<Depth extends number> = {
name: string
dropdownItems?: Depth > 0 ? MenuItem<Depth - 1>[] : never
}Describe alternatives you've considered
import { Number } from 'ts-toolbelt'
type MenuItem<Depth extends number> = {
name: string
dropdownItems: Number.Greater<Depth, 0> extends true ? MenuItem<Number.Sub<Depth, 1>>[] : never
}
const menuItem: MenuItem<1> = {
name: 'Products',
dropdownItems: [{
name: 'Edit',
}]
}However, this does not work. It looks like dropdownItems sets to never, and my menuItem variable fails.
Teachability, Documentation, Adoption, Migration Strategy
One thing that trips me up a bit: the docs use strings as the generics for Number.GreaterThan, but this doesn't seem to be in the types. Not sure if that's relevant: https://millsp.github.io/ts-toolbelt/modules/number_greatereq.html
Thanks again for your help!!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels