-
🍩 Feature RequestIs 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:
Is there a way I can self-reference a Describe the solution you'd likePseudocode (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 consideredimport { 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 Teachability, Documentation, Adoption, Migration StrategyOne thing that trips me up a bit: the docs use strings as the generics for Thanks again for your help!! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
I'm not sure if this is allowed, but looks like ignoring depth made it work: type Item = {
name: string
dropdownItems?: Item[]
}
const item: Item = {
name: 'Settings',
dropdownItems: [{
name: 'Notifications'
}]
} @millsp should I be concerned about infinite circular references like this, or is this okay to do? If this works, I'll close this issue. Thank you! |
Beta Was this translation helpful? Give feedback.
I'm not sure if this is allowed, but looks like ignoring depth made it work:
@millsp should I be concerned about infinite circular references like this, or is this okay to do? If this works, I'll close this issue. Thank you!