#help with generics

11 messages · Page 1 of 1 (latest)

scarlet martenBOT
#
piscopancer#0

Preview:```ts
function useTabs<Tabs extends string[]>({
initTab,
tabs,
}: {
initTab: Tabs[number]
tabs: Tabs
}) {}

const x = useTabs({
initTab: "",
tabs: ["security", "appearance", "profile"],
})```

frosty rover
#

...what's your question?

#

what do you need help with?

distant chasm
scarlet martenBOT
#
that_guy977#0

Preview:```ts
function useTabs<const Tabs extends readonly string[]>({initTab, tabs}: {initTab: Tabs[number], tabs: Tabs}) {

}

const x = useTabs({initTab: '', tabs: ['security', 'appearance', 'profile']})```

distant chasm
#

omg I have never seen you could put const and readonly inside a generic what the freaking hell

frosty rover
#

keep in mind that Tabs could be manually specified, so initTab may not be in tabs.

scarlet martenBOT
#
that_guy977#0

Preview:```ts
function useTabs<const Tabs extends readonly string[]>({initTab, tabs}: {initTab: Tabs[number], tabs: Tabs}) {

}

const x = useTabs<string[]>({initTab: '', tabs: ['security', 'appearance', 'profile']})```

frosty rover
distant chasm
#

!resloved