0

I would like to have a type that relates to an object with N level of nested keys and values being functions that returns strings.

Ideally I would like to have the value of the function being displayed in a tooltip instead of string type (od as a const shows me the value instead of string which I want) Like this bu this is very cumbersome.

const endpoints = {
  hierarchy: {
    od: () => `....` as const,
    sd: () => `.....`,
  },
  a: { b: { c: (a: string) => 'asdsd' } },
} as const

How I can make a type that would resolve to such structure?

4
  • take look at this stackoverflow.com/questions/42216053/… Commented Dec 19, 2022 at 17:52
  • Does this approach meet your needs? If so I could write up an answer explaining; if not, what am I missing? (Please mention @jcalz if you reply, to notify me) Commented Dec 19, 2022 at 22:40
  • @jcalz it's somewhat close but not exactly what I need. When I hover over the hierarchy key it shows me the values of the od sd but when I hover over od or sd it shows as string, secondly it allows me to define a key with any value so it can be a: 1 but I need it to conform only to the key: function with return type of string always Commented Dec 20, 2022 at 9:43
  • 1) "when I hover over od or sd it shows as string" I cannot reproduce; can you demonstrate this? 2) For the other issue I'd take this approach. Let me know what to do here, especially with the hovering issue which I am not seeing; I see the string literal types only and not string in my IDE. (Pls ping via @jcalz) Commented Dec 20, 2022 at 16:32

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.