#Is it possible to generate types when calling an "init" function?

7 messages · Page 1 of 1 (latest)

toxic meteor
#

I've made a super-small sandbox to demonstrate what I'd like to do:

https://www.typescriptlang.org/play?#code/PQKhAIBkEsCMCcCG8CeAocEMQCoAsBTcAAwGVoAvA48AFxQAciATApgO2YGdwB7duoXABhflwCuAWwLxwAN2TREsADZFiXSgS7Fs4ABK8A7uADGiAUZYFTvcQzXhotAPzZg4NAQAeDXvFo6RiJyKnAAXnAAawIUXgAzIKYE8E0qLgBuNFt2LkDodmclFS0YBGQUCPAACl4GWi4ALnALFABKCIA+cABvNABIYA8AOlG3AF80NFAIUVypGT09AElwIwtA2l5wBkQuHkQzfnjoAHM6bdohEvLUABpBAgE8RDkiRFNTbR4tx6P4eA2TbBLjuTw5PKpLQ8SJ9fqwM7NHrgUCjYYgDzjO4DLiSRAqFRIlEgNEY8CTSYFIr40pwJCoappbRtLIQwJM5qhIiRADkCNOPIyQA

I'm a little lost as to how to approach this, I want to split out a library but have types created based on some initialiser function.

I've looked at experimentalDecorators, but am in over my head. I'd be grateful of any pointers here!

daring hawkBOT
#

@toxic meteor Here's a shortened URL of your playground link! You can remove the full link from your message.

oodavid#0

Preview:```ts
/** Library
*

  • The Size type depends on the Consumer
  • How can we decouple it?
    */
    export type Size = keyof typeof sizes;
    const initializeLibrary = (opts: any) => {
    // ...?
    }

/** Consumer
*

  • I want to pass a config to the library, then have access to the correct types
    ...```
pearl mountain
#

sounds like you might want generics?

#

!hb generics

daring hawkBOT
toxic meteor
#

I'll take a look and see if I can get that to work!

toxic meteor
#

!solved