#simplify type/interface declaration

8 messages · Page 1 of 1 (latest)

gentle trench
#

I have something similar to this I'm trying to find a better way without making manual interfaces below.

type Type = 'a' | 'b'

interface Block<T extends Type> {
  content: typeof someObject[T]['childObj']
  type: T
}

interface AType extends Block<'a'> {}

interface BType extends Block<'b'> {}

Here's a much more accurate example of what I'm trying to do if anybody could help. Ignore the syntax warning, i just did a quick repro, in my code the error doesn't exist

https://www.typescriptlang.org/play?#code/KYDwDg9gTgLgBAYwgOwM7wCbAGYEMCuANjAEKEQIDWAKgJ5jCoBccA3gFBxwEYCWELDly69kvGL1yEAwihjBkMAMoxc8wZ2FdsvQsAD6vDC3RRRAcwDcmrZHRgoFRqgv78UQiZhnkVm8NQIdwQDd084UwtrLQBfaOFkXABbYC8fPy44zV4k3HNUtn9RcUkZOQVlVXVCrS4pGDSo-y4+VDBCXFo3D0bfeK0dPUNjCO8m2oigqBDu8Mi+-yytRJTejLgluChgXAwUQloNLWKJKVlFCpU1AqFagAsYJLmxhdj+uBWC+fXNwPxkDAIcj4DD6Hj8I7CE6lc7yRRXaq3LR-AFAoKg4BJABGwFBYTW702XE+BM0m3kIAaNShYlOZQu8KqN2acAeT1Jb38JNG6XimwAbkZgAJqSJaTDyozrpCBroDEYObU-tNQj0eeNarQgjB8Dj9IKsBBhorMu9ud8+fEtfgdXqDcKZXBoWdJZVpaLhNbbQZ7UaFerXsIiR9kl8Xj9rFl2DB6MA4ABZfC8MgUGixuAAXjglGAWuwcBjDAg+aweCIpHIVDoDFQ1nYonkUDwITgJFwqGAKarsYAPNQ4KA4RhUAmk120wwAHzUrGVyjDAD8iqQDKpheFJZwBGI4+rjAA2tQALr7gBEzvpcLd8lPR-i65Y1Ej7HrFybuBbAEEQfxd+nBwow6tu2nZznuPanuCECntOrAxC+DbAO+LYAJK5Pkf4MAOlKASObYdphwAQTkeTADBbDwa+jbNnGABKOwYAA8sgByEdhQ54SBhEQdsuz7LQ5FwQhb40XAShBAC0jAhg358BAbEAQCnEEWBvaniigLSWCP7QbBlGIchcbUIOCk4UpwEqam4GnhSMCCfpIkfnGABqQryapWGKUB+GgVZam+vZwnUU5cAAJpBNQurAK5hqmRxFm+d2DAQV6UX6m5gXRumzlSEYhEjhmmgAD5wLJv4ecAxVwGhpGEVV9G7MxrEVVV4n-BgUnomV7l+QwVXGZSdVcCVMXCkNcAleF+CRTio09UlwCWEAA

https://codesandbox.io/embed/lingering-pine-imt3bs?file=/src/App.tsx&codemirror=1

proud vine
#

here's a riff:

cyan auroraBOT
#
mkantor#7432

Preview:ts export declare const defaultBlockTypes: { audio: { initialContentState: { file_id: string postprocessing_url: string source_url: string } name: string } image: { initialContentState: { alt: stri ...

proud vine
#

i removed aliases like AudioBlockType as you could instead use BlockType<'audio'> (and not having it means you only need to mention each type in one place, which might help with maintainability)

#

but such aliases could easily be reintroduced if they pull their weight

gentle trench
#

Wow, I'm pretty sure that's exactly what i was looking for. You're the best

#

!resolved